Designing the Task Reminder Application

217

Chapter 9: Designing the Task Reminder Application

If you do not add the activity to the ApplicationManifest.xml file, you receive a run-time exception informing you that Android cannot find the class the activity. Creating the addingediting layout The layout for adding and editing is fairly simple because the form contains very few fields. These fields are as follows: ✓ Title: The title of the task as it will show in the list view. ✓ Body: The body of the task. This is where the user would type in the details. ✓ Reminder Date: The date on which the user should be reminded of the task. ✓ Reminder Time: The time at which the user should be reminded on the reminder date. When complete and running on a device or emulator, the screen looks like Figure 9-1. Figure 9-1: The Add Edit Task Reminder screen. To create this layout, create a layout file in the reslayout directory with an appropriate name — I’m using reminder_edit.xml. To create this file, perform the following steps: 218 Part III: Creating a Feature-Rich Application

1. Right-click the reslayout directory and choose New➪Android XML File.

2. Provide the name in the File field. 3. Leave the default type of resource selected — Layout.

4. Leave the folder set to reslayout. 5. Set the root element to ScrollView.

6. Click the Finish button.

You now need to provide all the view definitions to build the screen that you see in Figure 9-1. To do this, type the code shown in Listing 9-3. Listing 9-3: The reminder_edit.xml File ?xml version=”1.0” encoding=”utf-8”? ScrollView xmlns:android=”http:schemas.android.comapkresandroid” android:layout_width=”fill_parent” android:layout_height=”fill_parent” ➝ 5 LinearLayout ➝ 6 android:orientation=”vertical” ➝ 7 android:layout_width=”fill_parent” android:layout_height=”fill_parent” TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”stringtitle” ➝ 12 EditText android:id=”+idtitle” android:layout_width=”fill_parent” android:layout_height=”wrap_content” ➝ 15 TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”stringbody” ➝ 18 EditText android:id=”+idbody” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:minLines=”5” android:scrollbars=”vertical” android:gravity=”top” ➝ 24 TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”stringdate” ➝ 27 Button android:id=”+idreminder_date” android:layout_height=”wrap_content” android:layout_width=”wrap_content” ➝ 31 TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”stringtime” ➝ 34 Button android:id=”+idreminder_time” 219

Chapter 9: Designing the Task Reminder Application