Android Tutorial

(avery) #1
Android Tutorial 347

setImageURI() method. Now that we’ve set up everything,we
assign the PetListAdapter to our ListView:

String asColumnsToReturn[] = {
Pets.PETS_TABLE_NAME + “.” + Pets.PET_NAME,
Pets.PETS_TABLE_NAME + “.” + Pets.PET_IMAGE_URI,
Pets.PETS_TABLE_NAME + “.” + Pets._ID,
Pets.PETS_TABLE_NAME + “.” + Pets.PET_IMAGE_ID,
PetType.PETTYPE_TABLE_NAME + “.” + PetType.PET_TYPE_NAME };
mCursor = queryBuilder.query(mDB, asColumnsToReturn, null, null,
null, null, Pets.DEFAULT_SORT_ORDER);
startManagingCursor(mCursor);
SetListAdapter adapter = new PetListAdapter(this, mCursor);
ListView av = (ListView) findViewById(R.id.petList);
av.setAdapter(adapter);


That’s about it. Note that you can also create the ListView item
layout programmatically (see the PetListItemView class and the
PetListAdapter.getView() method comments for more information).

Now you’ve seen how to leverage a content provider to make your
application more robust, but this example has scratched only the
surface of how powerful content providers can be.

Acting as a Content Provider

Do you have data in your application? Can another application do
something interesting with that data? To share the information
within your application with other applications, you need to make
the application a content provider by providing the standardized
content provider interface for other applications; then you must
register your application as a content provider within the Android
manifest file. The most straightforward way to make an application
Free download pdf