How to accept more than one value from Android Text Preference?

24 Views Asked by At

Below is the code i used to accept username and password from text preference. Problem is i have to accept first username save it and then password. Is there any easier way to aceept both username and password at the same time on one click . may be two text field on clicking user info and aceept them at the same time .

<EditTextPreference
    android:key="username"
    android:title="@string/pref_title_username"
    android:defaultValue="@string/pref_default_username"
    android:selectAllOnFocus="true"
    android:inputType="textCapWords"
    android:capitalize="words"
    android:singleLine="true"
    android:maxLines="1" />

<EditTextPreference
    android:key="password"
    android:title="@string/pref_title_password"
    android:defaultValue="@string/pref_default_password"
    android:selectAllOnFocus="true"
    android:inputType="textPassword"
    android:capitalize="words"
    android:singleLine="true"
    android:maxLines="1" />
1

There are 1 best solutions below

0
Harsh Modani On

EditTextPreferences are designed to take in only one string at a time. So you can't take in a username and a password at the same time (unless you're willing to do something like make the user enter it in a particular manner, and then parse it, which is kind of absurd). Another way is to simply use a custom Preference and make it input two strings via two EditTexts. However, the bottom line is that it is unintuitive to use a single Preference to change two settings. (I hope this wasn't too long to read)