A (175)

(Tuis.) #1

238 CHAPTER 7: Making Apps Interactive: Intents, Event Handling, and Menus


If you mouse-over the wavy yellow warning highlighting, the warning message informs you that
Android wants you to provide a “hint” to your users using the android:hint parameter inside of your


UI widget, which we will learn about in the next section of this chapter.

As you can see in the bottom part of Figure 7-19, you can click on the Graphical Layout Editor tab
and see the EditText UI widget, shown selected in light blue, and the android:layout_toRightOf
parameter, shown using a green arrow pointing to the right, as well as the Button UI widget, shown
highlighted using a light yellow color.


Giving an EditText Field a Hint for Your Users


The EditText UI widget class has a unique attribute or parameter called a “hint” which allows you
to suggest to your user what needs to be placed into this data entry field, rather than just having
a blank field next to the OK Button. This happens to be very handy for the UI we are designing
here as this parameter will allow us to advise the user regarding what type of data we want them
to enter into each data field. For the first EditView, the hint would be “Enter Number of Colonies:”
The android:hint parameter references a constant, so we will be creating hint
constants very soon.


Add a new line after your android:layout_margin parameter and type in android:h to bring up the
helper dialog containing all of the parameters that start with an “h” and select and double-click to
insert the hint parameter, as shown in Figure 7-20. Once you do this, the warning highlighting will
disappear, and you can specify the hint constant named hint_colony (which we will create
next) by using the following XML parameter mark-up:


android:hint="@string/hint_colony"


Figure 7-20. Add suggested android:hint parameter to suggest field contents and to remove warning

Free download pdf