Tour ListActivity

TourListActivity handles both the home page and the list of installed tours. To do this, it uses ViewFlipper - think of it as the guts of a TabActivity, minus the tabs. Given a ViewFlipper and the appropriate means to get from view to view, this shows how you can build an arbitrarily complex activity instead of treating each individual activity as a separate construct.

In the layout (res/layout/main.xml), we declare a ViewFlipper. Each child element of the ViewFlipper represents a separate "page" to be flipped

between. You flip between them via the child's 0-based index, as illustrated in showList (), which toggles the view to the list of available tours:

private void showList() {

flipper.setDisplayedChild(0); setTitle("TourIt! - Tours");

flipMenu.setTitle("Go Home"); flipMenu.setIcon(R.drawable.home);

The tour list itself is a simple Listview, backed by a simpleCursorAdapter, in turn backed by the content provider. However, we do tailor the look of the individual list entries, by referencing our own layout (res/layout/tourlist_item.xml):

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/textl" android:layout_width="fill_parent"

android:layout_height="?android:attr/listPreferredltemHeight" android:textAppearance="?android:attr/textAppearanceLargeInverse" android:gravity="center_vertical" android:paddingLeft="5dip"

Self Publishing

Self Publishing

Have you always wanted to write your own book and get it published? Discover How to Write, Print Sell Your Own Book! Have you always wanted to write your own book and get it published? If you have written a book or even if you have a yen to be a writer, you are probably already aware of the competition in the writing field.

Get My Free Ebook


Post a comment