[英]how to access widgets set in layout using preference activity
i am creating preference Activity, in that i am adding custom preference screen using layout and i want to update values dynamically. 我正在创建首选项活动,因为我正在使用布局添加自定义首选项屏幕,并且我想动态更新值。
Here's the code : 这是代码:
<PreferenceCategory
android:key="more_category"
android:title="More Wallpapers " >
<Preference
android:key="more_apps"
android:layout="@layout/more_apps" />
Here is my layout more_apps.xml 这是我的布局more_apps.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/image_one"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/description_text"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_below="@+id/title_text"
android:layout_toRightOf="@+id/image_one"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/image_one"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/launcher" />
I want to update my textview and image at run time, how to access in preference activity? 我想在运行时更新textview和图像,如何在首选项活动中访问?
Please help 请帮忙
you need to use your mention your preference class in xml layout like the below code 您需要在xml布局中使用您提到的偏好类,如下面的代码
<PreferenceCategory
android:key="more_category"
android:title="More Wallpapers " >
<com.myapp.myclass android:key="more_apps"/>
</PreferenceCategory>
com.myapp
is a package name and myclass
is java file where all your coding comes.. com.myapp
是一个程序包名称,而myclass
是一个包含所有编码的Java文件。
Here is the java code and inflated xml more_apps.xml
这是Java代码和膨胀的XML
more_apps.xml
public class myclass extends Preference {
public myclass(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected View onCreateView(ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.more_apps, null);
return view;
}
}
This way you can create your custom preference activity and do any stuff.. 这样,您可以创建自定义首选项活动并执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.