Android Programming Tutorials

(Romina) #1
Asking Permission to Place a Call

Step #4: Collect the Phone Number on the Detail Form................


If we actually want to have phone numbers, though, we need to actually


collect them on DetailForm.


First, update LunchList/res/layout/detail_form.xml to add the following


after the address row in our TableLayout:


<TableRow>
<TextView android:text="Phone:" />
<EditText android:id="@+id/phone" android:inputType="phone" />
</TableRow>

Notice that we are using android:inputType="phone" on the new EditText


widget. This will cause Android to use a soft keyboard set up for entering a


phone number (where available), rather than a standard keyboard layout.


Similarly, add the following after the address row in LunchList/res/layout-


land/detail_form.xml:


<TableRow>
<TextView android:text="Phone:" />
<EditText android:id="@+id/phone"
android:inputType="phone"
android:layout_span="3"
/>
</TableRow>

Then, as in the previous section, clone all references to address in


DetailForm to make references to our phone widgets, such as:


EditText address=null;
EditText phone=null;

and:


address=(EditText)findViewById(R.id.addr);
phone=(EditText)findViewById(R.id.phone);

Also, it is safe for you to go ahead and get rid of the implementations of


onSaveInstanceState() and onRestoreInstanceState().


342
Free download pdf