Android Programming Tutorials

(Romina) #1
Getting More Active

break;
case R.id.take_out:
type="take_out";
break;
case R.id.delivery:
type="delivery";
break;
}
}
};

Step #4: Clean Up the Original UI.....................................................


Now we need to clean up LunchList and its layout to reflect the fact that we


moved much of the logic over to DetailForm.


First, get rid of the tabs and the detail form from


LunchList/res/layout/main.xml, and alter the ListView's android:id to


something suitable for ListActivity, leaving us with:


<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

Next, delete LunchList/res/layout_land/main.xml, as we will revisit


landscape layouts in a later tutorial.


At present, LunchList extends TabActivity, which is no longer what we need.


Change it to extend ListActivity instead, adding an import for


android.app.ListActivity.


Finally, get rid of the code from onCreate() that sets up the tabs and the


Save button, since they are no longer needed. Also, you no longer need to


find the ListView widget, since you can call setListAdapter() on the


ListActivity to associate your RestaurantAdapter with the ListActivity's


ListView. The resulting onCreate() implementation should look like:


114
Free download pdf