Time for action - setting up the ListView

We now have implementations to create both types of ListAdapter that this Activity can filter. Now we need a utility method to figure out which one to use, and return it; and then we want to use the new utility method to set the ListAdapter on the ListView widget.

  1. Declare a new method to create the desired ListAdapter object:
    protected ListAdapter createListAdapter() {
    
  2. Fetch the Intent object that was used to start the Activity:
    Intent intent = getIntent();
    
  3. If the data Uri in the Intent is not null, return a CursorAdapter for the given Intent. Otherwise, return an ArrayAdapter for the given Intent:
    if(intent.getData() != null) { return createCursorAdapter(intent); else { return createArrayAdapter(intent); ...

Get Android User Interface Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.