PreferenceScreen加载一个自定义布局layout,怎么设置监听 Android布局异常Preference 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 .xml:<Button android:id="@+id/btnUpdate" android:layout_width="112dp" android:layout_height="wrap_content" android:text="Update" android:onClick="doUpdate" />.java: public void doUpdate(View v) { ... } 应该是引用布局中的的button控件 这几天刚遇到同样的功能,搜到你也遇到同样的问题,解决了,顺便把我解决的方法贴出来,应该对你有用。你是要在一个Preference里加载一个自定义布局,可以这样做:自己写一个类TextPreference,继承Preference,调用自定义布局文件如下:<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/storage_settings_title" > <PreferenceCategory android:key="phone_memory_category" android:title="@string/storage_settings_title" > <com.android.settings.deviceinfo.TextPreference //自定义类 android:fragment="com.android.settings.deviceinfo.Memory" android:key="phone_memory_ll" /> </PreferenceCategory> </PreferenceScreen>在TextPreference类里面复写onCreateView方法,protected View onCreateView(ViewGroup parent) { // TODO Auto-generated method stub LayoutInflater inflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.phone_memory_linear_layout, null); mMaxTitle = (TextView)layout.findViewById(R.id.max_title); return layout; }然后你就可以欢快滴findViewById了。不是为了分,为了同样苦逼的IT民工吧。 Activity继承PreferenceActivityaddPreferencesFromResource(R.xml.preference);//这句加载自定义的Preference文件Button btn=(Button) findPreference("btnKey");//这里就像findViewById一样,不过这里的id其实是key的值..这样就得到了xml中控件了,之后想怎么操作就怎么操作了! 发送一条腾讯微博 验证 Android Pad 是否真正进入了suspend 如何实现expandlistview子item值动态刷新 紧急:如何将屏幕上的图片隐藏,谢了? 请教怎么绘制实时地图 post乱码问题 android 怎样实现从文本框获得用户名和密码,自动登录网站? eclipse 搜索中文字符用正则添加到行尾(即+注释;//匹配到的中文字符) android 修改系统默认输入法和日期格式 LitePal 可以使用外部DB数据库文件(assets或者raw目录下数据库表)么? 关于layout的短缺 SD卡文件夹下,有几千个录音文件,删除极慢,怎么解决?
<Button
android:id="@+id/btnUpdate"
android:layout_width="112dp"
android:layout_height="wrap_content"
android:text="Update"
android:onClick="doUpdate" />.java:
public void doUpdate(View v) {
...
}
你是要在一个Preference里加载一个自定义布局,可以这样做:
自己写一个类TextPreference,继承Preference,调用自定义布局文件如下:<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/storage_settings_title" >
<PreferenceCategory
android:key="phone_memory_category"
android:title="@string/storage_settings_title" > <com.android.settings.deviceinfo.TextPreference //自定义类
android:fragment="com.android.settings.deviceinfo.Memory"
android:key="phone_memory_ll"
/>
</PreferenceCategory>
</PreferenceScreen>在TextPreference类里面复写onCreateView方法,
protected View onCreateView(ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.phone_memory_linear_layout, null);
mMaxTitle = (TextView)layout.findViewById(R.id.max_title);
return layout;
}
然后你就可以欢快滴findViewById了。
不是为了分,为了同样苦逼的IT民工吧。
Activity继承PreferenceActivity
addPreferencesFromResource(R.xml.preference);//这句加载自定义的Preference文件
Button btn=(Button) findPreference("btnKey");//这里就像findViewById一样,不过这里的id其实是key的值..这样就得到了xml中控件了,之后想怎么操作就怎么操作了!