Wednesday, 30 January 2013

Clean Up the Original UI | Android Tutorial pdf

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. Y ou also no longer need to access the form widgets, since they are no longer in this activity. The resulting onCreate() implementation should look like:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
helper=new RestaurantHelper(this);
model=helper.getAll();
startManagingCursor(model);
adapter=new RestaurantAdapter(model);
setListAdapter(adapter);
}

No comments: