Question

I have a class that is already extending TabActivity so i can't extend ListActivity.

This hasn't be a problem until i needed to use this method:

private static int[] TO = { R.id.catItem, R.id.budgetAmount, };
private void showBudgetOutcome(Cursor cursor) {
//Set up data binding 
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this, R.layout.itemsforbudgetlist, cursor, FROM, TO);
setListAdapter(adapter);

}

Obviously setListAdapter is undefined. Now i found this snippet of code searching SO

mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

But i don't really understand the parameters. I tried altering it to suit me:

incomeView.setAdapter(new SimpleCursorAdapter<String>(this, R.layout.itemsforbudgetlist, adapter??));

I see that mListView is just the users ListView so i replaced that, and the layout resource defining how each item in the list looks i guess. But the rest i'm not sure about. I figure maybe i want a Simple/CursorAdapter since i'm working with sqlite (see my method)? but i have no idea what COUNTRIES is meant to be and not sure what data type i need (presumably string but what do i know). So if someone could clear things up for me and tell me how to use it with my method above i'd be really greatful!

Was it helpful?

Solution

If you want to pull your data from a database you need to subclass CursorAdapter. Then you can just call:

incomeView.setAdapter(new MyCursorAdapter(WhatEver arguments, You need));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top