Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom EditTextPreference

I want to customize my EditTextPreference, so i added a TextView in the left of my 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" />

That's what i get in my application:

enter image description here

And i want to customize my EditTextPreference, that's what i want to get:

enter image description here

I want to add the number in 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 the 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" />
like image 243
haythem souissi Avatar asked Oct 06 '22 07:10

haythem souissi


1 Answers

For you second question, why you do not use a number picker instead of this edittext ?

Example (from android.dev) Example

and code like this :

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 a customPreference. You can take example from IconPreferenceScreen which is in the settings menu.

like image 131
Goo Avatar answered Oct 10 '22 01:10

Goo