android - Dynamically change data of Custom PreferenceScreen -
i working on custom preferencescreen
, have created custom screen settings page using preferenceactivity
.
below preference screen.
issue:- need change badge of download data dynamically. followed question achieve layout. tried answer of question not working single answer.
is there other way find view inside preference?
settings.xml
<?xml version="1.0" encoding="utf-8"?> <preferencescreen xmlns:android="http://schemas.android.com/apk/res/android"> <preference android:title="@string/settings_user_profile" android:key="user_profile" android:summary="@string/settings_user_profile_desc" android:layout="@layout/setting_list"></preference> <preference android:title="@string/settings_download" android:key="download_data" android:summary="@string/settings_download_desc" android:layout="@layout/setting_list"></preference> </preferencescreen>
you can subclass preference
, overriding onbinddialogview()
- remember change xml <preference...>
include package , class <com.example.app.badgedpreference...>
:
@override protected void onbinddialogview(view v) { super.onbinddialogview(v); log.v( "onbinddialogview()", v.getclass().getsimplename() ); }
if badgedpreference
has method handling change, can use bit more - within preferenceactivity
:
preferencescreen myprefscreen = (preferencescreen)getpreferencescreen(); badgedpreference bp = (badgedpreference)myprefscreen.findpreference("download_data"); // custom method bp.setbadgevalue(12);
even more simply, can use standard preference
, style summary field 'badge', can set value using included summary field:
preference pref = (preference)myprefscreen.findpreference("download_data"); pref.setsummary("12");
let me know if have questions.
Comments
Post a Comment