I have created a custom EditTextPreference:
<EditTextPreference
android:key="alert_planed_edittext_preference"
android:title="@string/alert_planed_edittext_preference"
android:summary="@string/alert_planed_summary_edittext_preference"
android:dialogTitle="@string/alert_planed_dialog_title_edittext_preference"
android:numeric="integer"
android:layout="@layout/edit_text_preference_layout" />
the custom layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/alert_planed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:text="5" >
</TextView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="10dip"
android:layout_marginTop="6dip" >
<TextView
android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@android:id/title"
android:layout_below="@android:id/title"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</RelativeLayout>
I just added the text view with id alert_planed.
In my preference activity i am trying to get the new EditTextPreference value and put it in my text view alert_planed. I am getting the EditTextPreference value, that's ok. But when i set the text i got a null exception telling me that the TextView is null.
Here is my Preference code:
addPreferencesFromResource(R.xml.preferences);
mTextViewAlertPlanned = (TextView) findViewById(R.id.alert_planed);
findPreference("alert_planed_edittext_preference").setOnPreferenceChangeListener(new OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(
android.preference.Preference arg0, Object value) {
if(value != null)
{
Log.i("Preference","String.valueOf(value) ="+String.valueOf(value));
Log.i("Preference","mTextViewAlertPlanned ="+mTextViewAlertPlanned);
int myVal = Integer.parseInt(String.valueOf(value));
mTextViewAlertPlanned.setText(myVal);
}
return true;
}
});
How can i get my TextView correctly (the TextView is a part of the custom EditTextPreference layout)?