Recipe Providing Text Entry

The EditText class provides a simple view for user input. It can be declared just like a TextView with the most useful attributes shown in Table 4.4. Although each does have a corresponding Java method, it is less illuminating to show those here.

Table 4.4 Useful EditText Attributes in Addition to Those in Table 4.3. Again the Default Values Are in Bold in the Last Column.

EditText Attribute XML Element

Minimum number of lines to display android:minLines

Possible and Default Values

Any integer

Maximum number of lines to display android:maxLines Any integer

Hint text to show when display empty android:hint Any string

Input type android:inputType text textCapSentences textAutoCorrect textAutoComplete textEmailAddress textNoSuggestions textPassword number phone date time

For example, using the following XML code in a layout file shows a text entry window with "Type text here" displayed in grayed out text as a hint. On devices without a keyboard or on those where the keyboard is hidden, selecting the Edit window brings up the soft keyboard for text entry, as shown in Figure 4.8.

<EditText android:id="@+id/text_result" android:inputType="text"

android:textSize="30sp" android:hint="Type text here" android:layout_width="fill_parent" android:layout_height="wrap_content" />

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment