Game Development Reference
In-Depth Information
Figure 4-2. Our test starter activity, which looks fancy but doesn't do a lot yet
Now let's make something happen when a list item is touched. We want to start the respective
activity that is represented by the list item we touched.
Starting Activities Programmatically
The ListActivity class has a protected method called onListItemClick() that will be called
when an item is tapped. All we need to do is override that method in our AndroidBasicsStarter
class. And that's exactly what we did in Listing 4-1.
The arguments to this method are the ListView that the ListActivity uses to display the items,
the View that got touched and that's contained in that ListView , the position of the touched
item in the list, and an ID, which doesn't interest us all that much. All we really care about is the
position argument.
The onListItemClicked() method starts off by being a good citizen and calls the base class
method first. This is always a good thing to do if we override methods of an activity. Next, we
fetch the class name from the tests array, based on the position argument. That's the first
piece of the puzzle.
Earlier, we discussed that we can start activities that we defined in the manifest file
programmatically via an intent. The Intent class has a nice and simple constructor to do this,
 
Search WWH ::




Custom Search