conditional PreferenceCategory

0

I'm doing an app in which I'm using Preference and I'd like to show in PreferenceCategory only a title of several that are available, the selection of the title could be through a conditional, but how to do it, can you?

This is my Preference.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
    android:title="OPCION1"
    android:layout="@layout/setup_txt" >
</PreferenceCategory>

<PreferenceCategory
    android:title="OPCION2"
    android:layout="@layout/setup_txt" >
</PreferenceCategory>

<PreferenceCategory
    android:title="OPCION3"
    android:layout="@layout/setup_txt" >
</PreferenceCategory>

<PreferenceCategory
    android:title="OPCION4"
    android:layout="@layout/setup_txt" >
</PreferenceCategory>

    
asked by W1ll 22.11.2018 в 21:48
source

1 answer

1

You have to add an android: key:

 <PreferenceCategory 
      android:title="OPCION1"
      android:key="opcion1" 
      android:layout="@layout/setup_txt" >
 </PreferenceCategory>

So that in java you locate it like this:

 PreferenceCategory prefeCategory = (PreferenceCategory)findPreference("opcion1");
  // código para if/else ...
 prefeCategory.setTitle("Tu_Nuevo_Titulo");
    
answered by 22.11.2018 / 23:00
source