Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we use android:inputType in EditTextPreference?

I checked the documentation of EditTextPreference http://developer.android.com/reference/android/preference/EditTextPreference.html

But I failed to found the android:inputType attribute there. Then how it can be used in this code segment

<EditTextPreference
        android:key="edit"
        android:title="@string/location1"
        android:summary="@string/summary1"
        android:dialogTitle="@string/location1"
        android:dialogMessage="@string/message"
        android:inputType="text"
        android:singleLine="true"
        />

Same doubt for the android:singleLine attribute.

like image 249
Nitish Chopra Avatar asked Jul 10 '15 21:07

Nitish Chopra


People also ask

What does android InputType do?

The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.

What is EditText in android?

A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.

Which attribute of EditText tells the system keyboard what kind of input you are expecting *?

Setting the InputType of an EditText tells the system keyboard what kind of input you are expecting. If your edit text is for inputting a phone number, then you want the keyboard to show numbers.


2 Answers

The docs don't list the attributes for that class, but the InputType attribute (and other EditText and TextView attributes) still work. It's only stated in the text. Also see this related question.

The EditTextPreference documentation doesn't explicitly list all the attributes it supports, but the text states:

See EditText Attributes.

The link there isn't very useful (they probably reorganised some of the attributes but never updated some links to it), but here's a direct link to inputType values. As a quick summary those values are (as of the time of posting):

  • none
  • text
  • textCapCharacters
  • textCapWords
  • textCapSentences
  • textAutoCorrect
  • textAutoComplete
  • textMultiLine
  • textImeMultiLine
  • textNoSuggestions
  • textUri
  • textEmailAddress
  • textEmailSubject
  • textShortMessage
  • textLongMessage
  • textPersonName
  • textPostalAddress
  • textPassword
  • textVisiblePassword
  • textWebEditText
  • textFilter
  • textPhonetic
  • textWebEmailAddress
  • textWebPassword
  • number
  • numberSigned
  • numberDecimal
  • numberPassword
  • phone
  • datetime
  • date
  • time

You can apparently use one or more of these, separated by a | (I've never done this though).

like image 85
Laogeodritt Avatar answered Sep 19 '22 23:09

Laogeodritt


You can't do it from XML, but EditTextpreference exposes the EditText so you can do it programmatically. After you load the preferences in your Activity/Fragment, you can do:

EditTextPreference pref = (EditTextPreference) PreferenceManager.findPreference("edit");
EditText prefEditText = pref.getEditText();
prefEditText.setInputType(InputType.TYPE_CLASS_TEXT);
prefEditText.setSingleLine(true);
// etc
like image 31
Karakuri Avatar answered Sep 17 '22 23:09

Karakuri