カスタム 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" />
カスタム レイアウト コード:
<?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>
IDがalert_planedのテキストビューを追加しました。
私の設定アクティビティでは、新しい EditTextPreference 値を取得して、テキスト ビュー alert_planed に入れようとしています。EditTextPreference 値を取得しています。問題ありません。しかし、テキストを設定すると、TextView が null であることを示す null 例外が発生しました。
これが私の設定コードです:
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;
}
});
TextView を正しく取得するにはどうすればよいですか (TextView はカスタム EditTextPreference レイアウトの一部です)。