9

I was wondering if there was a way to change the

PreferenceCategory android:title="my name"

programmatically and or the

ListPreference android:title="my name"

programmatically.

j0k
  • 22,600
  • 28
  • 79
  • 90
Keith
  • 261
  • 1
  • 3
  • 8

1 Answers1

19

Keith,

Yes, there is a way to change the title programmatically. You must add a android:key="myTag" in your xml layout for the PreferenceCategory. Then you can access the PreferenceCategory from code by using findPreference("myTag"). The code is below:

XML:

<PreferenceCategory android:title="My Preferences"
   android:key="myPreferencesTitle" 
>

Java code:

PreferenceCategory prefCat=(PreferenceCategory)findPreference("myPreferencesTitle");
prefCat.setTitle("My New Title");

Hope this helps.

Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141
  • 1
    Thanks Patrick, I was trying to use `findViewById` and your answer was just what I was looking for :-) – Jared Feb 23 '12 at 23:54