自定义preference.docx
《自定义preference.docx》由会员分享,可在线阅读,更多相关《自定义preference.docx(16页珍藏版)》请在冰点文库上搜索。
自定义preference
AndroidManifest.xml:
xmlversion="1.0"encoding="utf-8"?
>
android=" package="com.mylotto" android:versionCode="1" android:versionName="1.0.0"> icon="@drawable/icon"android:label="@string/app_name"> name="Smsdealer"> --設定要捕捉的訊息名稱為provider中Telephony.SMS_RECEIVED--> android:name="android.provider.Telephony.SMS_RECEIVED"/> android:name=".Mylotto" android:exported="true" android:process=":locate"> minSdkVersion="7"/>name="android.permission.RECEIVE_SMS">name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
android="
package="com.mylotto"
android:
versionCode="1"
versionName="1.0.0">
icon="@drawable/icon"android:label="@string/app_name"> name="Smsdealer"> --設定要捕捉的訊息名稱為provider中Telephony.SMS_RECEIVED--> android:name="android.provider.Telephony.SMS_RECEIVED"/> android:name=".Mylotto" android:exported="true" android:process=":locate"> minSdkVersion="7"/>name="android.permission.RECEIVE_SMS">name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
icon="@drawable/icon"android:
label="@string/app_name">
name="Smsdealer"> --設定要捕捉的訊息名稱為provider中Telephony.SMS_RECEIVED--> android:name="android.provider.Telephony.SMS_RECEIVED"/> android:name=".Mylotto" android:exported="true" android:process=":locate"> minSdkVersion="7"/>name="android.permission.RECEIVE_SMS">name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
name="Smsdealer">
--設定要捕捉的訊息名稱為provider中Telephony.SMS_RECEIVED-->
android:name="android.provider.Telephony.SMS_RECEIVED"/> android:name=".Mylotto" android:exported="true" android:process=":locate"> minSdkVersion="7"/>name="android.permission.RECEIVE_SMS">name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
name="android.provider.Telephony.SMS_RECEIVED"/>
android:name=".Mylotto" android:exported="true" android:process=":locate">
name=".Mylotto"
exported="true"
process=":
locate">
minSdkVersion="7"/>name="android.permission.RECEIVE_SMS">name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
minSdkVersion="7"/>
name="android.permission.RECEIVE_SMS">name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
name="android.permission.RECEIVE_SMS">
name="android.permission.SEND_SMS">Mylotto.java:packagecom.mylotto;importandroid.app.PendingIntent;importandroid.app.Service;importandroid.content.Intent;importandroid.os.Bundle;importandroid.os.IBinder;importandroid.telephony.SmsManager;publicclassMylottoextendsService{ @Override publicIBinderonBind(Intentintent){ returnnull; } publicvoidonCreate(){ super.onCreate(); } publicvoidonStart(Intentintent,intstartId){ super.onStart(intent,startId); Bundlebunde=intent.getExtras(); Stringto=bunde.getString("caller"); SmsManagersms=SmsManager.getDefault(); PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0); sms.sendTextMessage(to,null,"seccess",sentPI,null); super.stopSelf(startId); } @Override publicvoidonDestroy(){ super.onDestroy(); }}Smsdealer:packagecom.mylotto;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.telephony.SmsMessage;/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/ publicclassSmsdealerextendsBroadcastReceiver { /*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/ privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED"; @Override publicvoidonReceive(Contextcontext,Intentintent) { //TODOAuto-generatedmethodstub /*判断传来Intent是否为短信*/ if(intent.getAction().equals(mACTION)) { /*构造一个字符串变量sb*/ StringBuildersb=newStringBuilder(); /*接收由Intent传来的数据*/ Bundlebundle=intent.getExtras(); /*判断Intent是有资料*/ if(bundle!=null) { /*pdus为android内建短信参数identifier *透过bundle.get("")并传pdus的对象*/ Object[]myOBJpdus=(Object[])bundle.get("pdus"); /*构造短信对象array,并依据收到的对象长度来建立array的己弋*/ SmsMessage[]messages=newSmsMessage[myOBJpdus.length]; for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
name="android.permission.SEND_SMS">
Mylotto.java:
packagecom.mylotto;
importandroid.app.PendingIntent;
importandroid.app.Service;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.os.IBinder;
importandroid.telephony.SmsManager;
publicclassMylottoextendsService{
@Override
publicIBinderonBind(Intentintent){
returnnull;
}
publicvoidonCreate(){
super.onCreate();
publicvoidonStart(Intentintent,intstartId){
super.onStart(intent,startId);
Bundlebunde=intent.getExtras();
Stringto=bunde.getString("caller");
SmsManagersms=SmsManager.getDefault();
PendingIntentsentPI=PendingIntent.getBroadcast(this,0,newIntent(),0);
sms.sendTextMessage(to,null,"seccess",sentPI,null);
super.stopSelf(startId);
publicvoidonDestroy(){
super.onDestroy();
Smsdealer:
importandroid.content.BroadcastReceiver;
importandroid.content.Context;
importandroid.telephony.SmsMessage;
/*自定义继承自BroadcastReceiver类,监听系统服务广播的信息*/
publicclassSmsdealerextendsBroadcastReceiver
{
/*声明静态字符串,并使用android.provider.Telephony.SMS_RECEIVED作为Action为短信的依据*/
privatestaticfinalStringmACTION="android.provider.Telephony.SMS_RECEIVED";
publicvoidonReceive(Contextcontext,Intentintent)
//TODOAuto-generatedmethodstub
/*判断传来Intent是否为短信*/
if(intent.getAction().equals(mACTION))
/*构造一个字符串变量sb*/
StringBuildersb=newStringBuilder();
/*接收由Intent传来的数据*/
Bundlebundle=intent.getExtras();
/*判断Intent是有资料*/
if(bundle!
=null)
/*pdus为android内建短信参数identifier
*透过bundle.get("")并传pdus的对象*/
Object[]myOBJpdus=(Object[])bundle.get("pdus");
/*构造短信对象array,并依据收到的对象长度来建立array的己弋*/
SmsMessage[]messages=newSmsMessage[myOBJpdus.length];
for(inti=0;i { messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]); } /*将送来的短信安并自定义信息在StringBuilder当中*/ for(SmsMessagecurrentMessage:messages) { if(currentMessage.getMessageBody().contains("getlocate")){ /*发信人的电话号码*/ sb.append(currentMessage.getDisplayOriginatingAddress()); /*取得传来短信的BODY*/ // sb.append(currentMessage.getDisplayMessageBody()); Stringto=currentMessage.getOriginatingAddress(); Intenti=newIntent(context,Mylotto.class); /*设定让加Activity以一个新的task来执行*/ Bundlenewb=newBundle(); newb.putString("caller",to); i.putExtras(newb); context.startService(i); } } } } }}Activity,Manifest,drawable,Intent,Service本帖地址: [复制链接]相关帖子 关于短信的问题,短信快速回复(源码)关于自动跳转的小问题短信彩信列表问题真机无法自动回复短信节日短信回复助手(附源码)节日短信回复助手源码android短信数据库查询的问题查看更多>>根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复分享到:QQ空间腾讯微博腾讯朋友淘帖0分享0收藏1好评0差评0转发到微博相关帖子•获取手机设备的唯一码(IMIE)•获得手机的IP地址代码段•一套关于游戏声音的解决方案•Android教程之MediaStore•Android应用初始化及窗体事件(按键)的分发•Alarm机制介绍•AndroidWidget开发(转)•请教一下Service•OPhoneWebAPI简介•扫描wifi热点回复举报zuo656zuo656当前离线在线时间712小时e望2点最后登录2012-9-12注册时间2010-2-20积分1840阅读权限50UID1993912主题2好友1840积分No.5砖家开发者No.5砖家开发者,积分1840,距离下一级还需1160积分升级 22.67%当前用户组为No.5砖家开发者当前积分为1840,升到下一级还需要1160点。精华0帖子108e币447元发消息沙发发表于2010-12-3010:43:44|只看该作者开个线程发送试试不要用service。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息板凳发表于2010-12-3011:00:19|只看该作者真惭愧,刚接触ANDROID才一个星期。怎么开个线程还不知道。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息地板发表于2010-12-3011:05:17|只看该作者我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。回复举报lottolotto当前离线在线时间1小时e望0点最后登录2010-12-30注册时间2010-11-26积分20阅读权限10UID1111791主题0好友20积分No.1开发小菜鸟No.1开发小菜鸟,积分20,距离下一级还需80积分升级 20%当前用户组为No.1开发小菜鸟当前积分为20,升到下一级还需要80点。精华0帖子4e币15元发消息5楼发表于2010-12-3013:28:50|只看该作者回复zuo656的帖子谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。太感谢你了。这个东西困扰了我几天。但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:请看中间选项的效果,在右边显示当前选择的图片。代码如下:1.import android.content.Context; 2.import android.content.Intent; 3.import android.os.Bundle; 4.import android.preference.Preference; 5.import android.preference.PreferenceActivity; 6.import android.util.AttributeSet; 7.import android.view.View; 8.import android.widget.ImageView; 9. 10. 11.public class ImageOptionPreference extends Preference { 12. 13. private PreferenceActivity parent; 14. private int mImage = R.drawable.car; 15. private ImageView preview_img; 16. 17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) { 18. super(context, attrs, defStyle); 19. } 20. 21. public ImageOptionPreference(Context context, AttributeSet attrs) { 22. super(context, attrs); 23. } 24. 25. public ImageOptionPreference(Context context) { 26. super(context); 27. } 28. 29. void setActivity(PreferenceActivity parent) { 30. this.parent = parent; 31. } 32. 33. @Override 34. public boolean isPersistent() { 35. return false; 36. } 37. 38. 39. boolean ChangeGamePic(int newImage ){ 40. preview_img.setImageResource(newImage); 41. return true; 42. } 43. 44. @Override 45. protected void onBindView(View view) { 46. super.onBindView(view);47. SharedPreferencesmPerferences=getContext().getSharedPreferences( "com.jiubang.tile_preferences",Context.MODE_PRIVATE); intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1); preview_img=(ImageView)view.findViewById(R.id.pref_current_img); preview_img.setImageResource(backgroundPosition);48. } 49. @Override 50. protected void onClick() { 51. super.onClick(); 52. } 53.} 对应的Perference.xml配置信息如下 android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
messages[i]=SmsMessage.createFromPdu((byte[])myOBJpdus[i]);
/*将送来的短信安并自定义信息在StringBuilder当中*/
for(SmsMessagecurrentMessage:
messages)
if(currentMessage.getMessageBody().contains("getlocate")){
/*发信人的电话号码*/
sb.append(currentMessage.getDisplayOriginatingAddress());
/*取得传来短信的BODY*/
// sb.append(currentMessage.getDisplayMessageBody());
Stringto=currentMessage.getOriginatingAddress();
Intenti=newIntent(context,Mylotto.class);
/*设定让加Activity以一个新的task来执行*/
Bundlenewb=newBundle();
newb.putString("caller",to);
i.putExtras(newb);
context.startService(i);
Activity,Manifest,drawable,Intent,Service
本帖地址:
[复制链接]
相关帖子
关于短信的问题,
短信快速回复(源码)
关于自动跳转的小问题
短信彩信列表问题
真机无法自动回复短信
节日短信回复助手(附源码)
节日短信回复助手源码
android短信数据库查询的问题
查看更多>>
根据关键字回复信息android短信阷鎖字自动发短信短信启动service自动回复短信自动回复android如何关闭自动回复短信android开发自动回复短信android收到短信后自动回复短信android收到短信自动回复
分享到:
QQ空间
腾讯微博
腾讯朋友
淘帖0
分享0
收藏1
好评0
差评0
转发到微博
•获取手机设备的唯一码(IMIE)
•获得手机的IP地址代码段
•一套关于游戏声音的解决方案
•Android教程之MediaStore
•Android应用初始化及窗体事件(按键)的分发
•Alarm机制介绍
•AndroidWidget开发(转)
•请教一下Service
•OPhoneWebAPI简介
•扫描wifi热点
回复
举报
zuo656
zuo656当前离线
在线时间
712小时
e望
2点
最后登录
2012-9-12
注册时间
2010-2-20
积分
1840
阅读权限
50
UID
19939
12
主题
2
好友
No.5砖家开发者
No.5砖家开发者,积分1840,距离下一级还需1160积分
升级
22.67%
当前用户组为No.5砖家开发者
当前积分为1840,升到下一级还需要1160点。
精华
0
帖子
108
e币
447元
发消息
沙发
发表于2010-12-3010:
43:
44|只看该作者
开个线程发送试试不要用service。
lotto
lotto当前离线
1小时
0点
2010-12-30
2010-11-26
20
10
111179
1
No.1开发小菜鸟
No.1开发小菜鸟,积分20,距离下一级还需80积分
20%
当前用户组为No.1开发小菜鸟
当前积分为20,升到下一级还需要80点。
4
15元
板凳
发表于2010-12-3011:
00:
19|只看该作者
真惭愧,刚接触ANDROID才一个星期。
怎么开个线程还不知道。
地板
05:
17|只看该作者
我会上网找找相关资料,尽管现在资料真少得可怜,无限感激。
5楼
发表于2010-12-3013:
28:
50|只看该作者
回复zuo656的帖子
谢谢这位朋友,很感谢,我在服务上,加上线程,就可以了。
太感谢你了。
这个东西困扰了我几天。
但这些组件毕竟还不能满足100%的要求,假设我们需要为应用程序提供一个选择不同图片做为应用背景图的设置,我们需要一个很直观的就可以看到当前所选择的图片,然后点击后可以浏览其他图片并选择。
那么这些Preference就无法满足这个需求,因此我们需要对Preference进行扩展,下图是扩展后的效果:
请看中间选项的效果,在右边显示当前选择的图片。
代码如下:
1.import android.content.Context;
2.import android.content.Intent;
3.import android.os.Bundle;
4.import android.preference.Preference;
5.import android.preference.PreferenceActivity;
6.import android.util.AttributeSet;
7.import android.view.View;
8.import android.widget.ImageView;
9.
10.
11.public class ImageOptionPreference extends Preference {
12.
13. private PreferenceActivity parent;
14. private int mImage = R.drawable.car;
15. private ImageView preview_img;
16.
17. public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) {
18. super(context, attrs, defStyle);
19. }
20.
21. public ImageOptionPreference(Context context, AttributeSet attrs) {
22. super(context, attrs);
23. }
24.
25. public ImageOptionPreference(Context context) {
26. super(context);
27. }
28.
29. void setActivity(PreferenceActivity parent) {
30. this.parent = parent;
31. }
32.
33. @Override
34. public boolean isPersistent() {
35. return false;
36. }
37.
38.
39. boolean ChangeGamePic(int newImage ){
40. preview_img.setImageResource(newImage);
41. return true;
42. }
43.
44. @Override
45. protected void onBindView(View view) {
46. super.onBindView(view);
47. SharedPreferencesmPerferences=getContext().getSharedPreferences(
"com.jiubang.tile_preferences",Context.MODE_PRIVATE);
intbackgroundPosition=mPerferences.getInt("background",R.drawable.bg_1);
preview_img=(ImageView)view.findViewById(R.id.pref_current_img);
preview_img.setImageResource(backgroundPosition);
48. }
49. @Override
50. protected void onClick() {
51. super.onClick();
52. }
53.}
对应的Perference.xml配置信息如下
android:key="game_pic" android:persistent="false" android:title="@string/pref_pic_title" android:summary="@string/pref_pic_summary" android:widgetLayout="@layout/preference_widget_image" /> 而preference_widget_image(在layout中)的信息如下xmlversion="1.0"encoding="utf-8"?>--LayoutusedbyImageOptionPreferencefortheimageoptionstyle. Thisisinflatedinsideandroid.R.layout.preference. -->android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
key="game_pic"
persistent="false"
title="@string/pref_pic_title"
summary="@string/pref_pic_summary"
widgetLayout="@layout/preference_widget_image"
/>
而preference_widget_image(在layout中)的信息如下
--LayoutusedbyImageOptionPreferencefortheimageoptionstyle.
Thisisinflatedinsideandroid.R.layout.preference.
-->
android=" android:id="@+id/pref_current_img" android:layout_width="54dip" android:layout_height="54dip" android:layout_marginRight="4dip" android:layout_gravity="center_vertical" android:focusable="false" android:clickable="false" android:background="#eeeeee" android:padding="2dip" />而这个ImageView的Layout就是在选项右边显示的图片。
id="@+id/pref_current_img"
layout_width="54dip"
layout_height="54dip"
layout_marginRight="4dip"
layout_gravity="center_vertical"
focusable="false"
clickable="false"
background="#eeeeee"
padding="2dip"
而这个ImageView的Layout就是在选项右边显示的图片。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2