Custom EditTextPreference

I want to customize mine EditTextPreference

, so I added TextView

on the left side of mine EditTextPreference

.

Here is my code:

<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" />

      

What I get in my application:

enter image description here

And I want to customize my EditTextPreference, which is what I want to get:

enter image description here

I want to add a number to the right, can I do that?

When I click I get this dialog:

enter image description here

I want the user to be allowed to select only numbers, how can I do that?

Edit: I found a solution for the second problem:

<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" />

      

+3


source to share


1 answer


For you the second question is, why don't you use a set of numbers instead of this edittext?

Example (from android.dev ) Example

and the code:



Public class NumberPickerPreference extends DialogPreference {
    public NumberPickerPreference(Context context, AttributeSet attrs) {
        super(context, attrs);

        setDialogLayoutResource(R.layout.numberpicker_dialog);
        setPositiveButtonText(android.R.string.ok);
        setNegativeButtonText(android.R.string.cancel);

        setDialogIcon(null);
    }
    ...
}

      

Regarding your first question, I have to implement customPreference. You can take an example from IconPreferenceScreen found in the preferences menu.

+4


source







All Articles