J'utilise PreferenceFragment
avec des préférences par défaut catégories et une mise en page personnalisée:TextView setText ne fonctionne pas sur la mise en page custome dans PreferenceFragment
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:key="first_category"
android:title="config" >
<EditTextPreference
android:defaultValue="example"
android:dialogMessage="text"
android:dialogTitle="Title"
android:key="mykey"
android:summary="summary"
android:title="title" />
<Preference
android:key="test_connection"
android:title="Test connection"
android:layout="@layout/test_conn" />
</PreferenceCategory>
</PreferenceScreen>
Ma mise en page de test_conn:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_weight="1" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:text="Test connection"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:text="Ko"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ff0000"
android:textStyle="bold" />
</RelativeLayout>
Je suis lire le texte R.id.summary
avec ce code:
addPreferencesFromResource(R.xml.preferences);
findPreference(TEST_CONN).setOnPreferenceClickListener(this);
Preference custom = findPreference(TEST_CONN);
customv = custom.getView(null, null);
res = (TextView) customv.findViewById(R.id.summary);
Je peux lire cor directement mon TextView, mais si j'essaie de changer le texte, par exemple dans une asynctask, je ne peux pas voir le texte changé.
Ceci est une partie de AsyncTask:
@Override
protected void onPostExecute(Boolean result) {
if (result == true){
res.setText("Ok");
res.setTextColor(Color.GREEN);
}
else {
res.setText("Ko");
res.setTextColor(Color.RED);
}
pdia.dismiss();
}
Lorsque l'utilisateur clique sur la préférence « test_connection », commence un AsyncTask et dans le Funzion onPostExecute je modifie le texte, mais ne fonctionne pas. Est-ce que je manque quelque chose? Devrais-je lire le textview avec une autre méthode?
Sky Il n'a pas fonctionné pour moi .. – Asthme