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
<?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?
Please help
you need to use your mention your preference class in xml layout like the below code
<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..
Here is the java code and inflated 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..
来源:https://stackoverflow.com/questions/10997007/how-to-access-widgets-set-in-layout-using-preference-activity