Hardware Reference
In-Depth Information
Part 1 of the XML file describes the overall layout style and the first
EditText
box along with the associated
information, such as IDs, fill, location, and relative layout type. The ID for the first
EditText
box is
incomingData
.
Because there is no need for the incoming-data box to be edited, the flags after the ID and positional definitions for this
EditText
box are set to turn off this functionality. The options for focus, cursor viability, and click ability of the box are
turned off by setting the associated Android flags to
false
. The next two options set a scroll bar to show when the text
has gone past the box's bottom edge. The gravity is set to the top so the incoming text does not sit centered. The flag
android:inputType
sets two options, telling the code that this box is a multiline box and that the spell check needs to be
turned off and not show any spelling suggestions. The last flag sets the hint to a string located in the
strings.xml
file.
Listing 4-12.
main.xml, Part 1 of 3
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
http://schemas.android.com/apk/res/android
"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.72" >
<EditText
android:id="@+id/incomingData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/outgoingData"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
android:gravity="top"
android:inputType="textMultiLine|textNoSuggestions"
android:hint="@string/hint" >
</EditText>
Part 2 describes the
EditText
box, which is to be used as the output box to send data to the Arduino. The box
will be identifiable to the code as
outgoingData
. The size is not described as absolute, as in the blink example, but as
dynamic compared to the other objects—this user interface will always use the available screen no matter the size.
The hint for this box is also set in the
strings.xml
file. Finally the input type is defined as text. This is a single-line
input box with the overflow continuing to scroll horizontally. This box also turns off the spell check.
Listing 4-12.
main.xml, Part 2 of 3
<EditText
android:id="@+id/outgoingData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/sendbutton"
android:hint="@string/sendhint"
android:inputType="text|textNoSuggestions" >
</EditText>