Search code examples
androidlayouttextviewpreferencespreferenceactivity

Android Preferences custom layout edit


I added custom layouts to my preferences. But now I want to change the text of a TextView inside a layout programmatically. How do I do that?

Now it looks like this:

final PreferenceScreen preference = (PreferenceScreen) findPreference(getString(R.string.key_of_my_prefernce));
preference.setLayoutResource(R.layout.my_preference);

Thank you


Solution

  • Have you tried?

    PreferenceManager prefmngr=preference.getPreferenceManager();
    TextView txt = (TextView)prefmngr.findPreference("the key of the textview in the preference tree").getView(convertView, parent);
    txt.setText("TEXT");
    

    http://developer.android.com/reference/android/preference/Preference.html#getView(android.view.View, android.view.ViewGroup)