Question

I have a ListFragment which displays a list of items obtained using a CursorLoader and a CursorAdapter as per the standard way of handling views of lists. This in itself is working fine,however I'm unsure as to how to use the same pattern to display the detailed view of a selected item.

A previous StackOverflow question discussed this but neither of the solutions suggested seem to me to be optimal. Using a ListView with a single item seems like overkill and wasteful of resources, whereas carrying out the work directly in the activity seems to be overloading the activity with data access and UI functionality. It also loses the ability to keep data in sync between the activity and the underlying storage.

Is there some middle ground that retains the split between loader, activity and adapter but for a single item rather than a list?

Was it helpful?

Solution

You can do without the Adapter and the ListView.

The CursorLoader returns you a Cursor. You can access the cursor without passing it to an adapter. Just make sure the Cursor contains at least your one row.

if (cursor != null && cursor.moveToFirst()) {
  // do whatever, ie String myString=cursor.getString(0)
  // in case you fetch a string as the first element of your projection  
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top