You can subclass Preference
, overriding onBindDialogView()
- just remember to change the XML from <Preference...>
to include your package and class <com.example.app.BadgedPreference...>
:
@Override
protected void onBindDialogView(View v) {
super.onBindDialogView(v);
Log.v( "onBindDialogView()", v.getClass().getSimpleName() );
}
If your BadgedPreference
has a method for handling your change, you can use it a bit more easily - from within your PreferenceActivity
:
PreferenceScreen myPrefScreen = (PreferenceScreen)getPreferenceScreen();
BadgedPreference bp = (BadgedPreference)myPrefScreen.findPreference("download_data");
// Custom method
bp.setBadgeValue(12);
Even more simply, you can use a standard Preference
, just style its summary field as a 'badge', then you can set the value using the included Summary field:
Preference pref = (Preference)myPrefScreen.findPreference("download_data");
pref.setSummary("12");
Let me know if you have any questions.