how-do-i-display-the-current-value-of-an-android-preference-in-the-preference-summary에 의해 영감을 얻은 저는 자신의 EditTextPreference를 만들었습니다.이 EditTextPreference는 PreferenceScreen에서 현재 값을 보여줍니다.현재 값을 가진 환경 설정 요약 사용자 정의 EditTextPreference : 현재 값을 얻는 방법?
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:key="preferences" xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="First Category"
android:key="first_category">
<de.k3b.widgets.EditTextPreferenceWithSummary
android:key="test"
android:title="Test Message"
android:dialogTitle="Test Message"
android:dialogMessage="Provide a message"
android:defaultValue="Default welcome message" />
</PreferenceCategory>
</PreferenceScreen>
구현은 PreferenceScreen 먼저 표시 전류 값이없는 도시이
package de.k3b.widgets;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.*;
import android.util.AttributeSet;
import android.util.Log;
public class EditTextPreferenceWithSummary extends EditTextPreference {
private final static String TAG = EditTextPreferenceWithSummary.class.getName();
public EditTextPreferenceWithSummary(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public EditTextPreferenceWithSummary(Context context) {
super(context);
init();
}
private void init() {
Log.e(TAG, "init");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getContext());
String currentText = test prefs.getString("minTrashholdInSecs", this.getText());
// where do i get the current value of the underlaying EditTextPreference ??
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
this.setSummary(this.getText());
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.w(TAG, "display score changed to "+newValue);
preference.setSummary(newValue.toString()); // getSummary());
return true;
}
});
}
}
같다.
내 문제 : 어디에서 EditTextPreference가 나타내는 현재 값을 얻을 수 있습니까? getText()는 예상 한 값을 가져 오지 않습니다. preferencevalue를 변경하면이 값이 요약 필드에 예상대로 표시됩니다.
임은 EditTextPreferenceWithSummary
클래스에 다음 코드를 추가 안드로이드 2.2
하나는 사실이 soulution은 나보다 더 우아하다. @Oleg Flores는 2012 년에 제 문제를 해결했기 때문에 대답을 받았습니다. – k3b