Android Preference: Show current value in summary

When creating android preference view, I found that the default preference like EditTextPreference does not show the current value as summary (and no way to make them do it). So I made the following class to help:

import android.content.Context;
import android.util.AttributeSet;

public class EditTextPreference extends android.preference.EditTextPreference {

	public EditTextPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	@Override
	protected void onDialogClosed(boolean positiveResult) {
		super.onDialogClosed(positiveResult);
		
		setSummary(getSummary());
	}

	@Override
	public CharSequence getSummary() {
		return this.getText();
	}
}
Advertisements