当前位置: 动力学知识库 > 问答 > 编程问答 >

java - how do you add subitems to a listView from a database

问题描述:

I have a database that stores the count of a tally and a name associated with that tally, I've gotten the list view to display the tally count but I can't figure out how to display the name as a sub item.

Here is my code so far.

public class SavedScreen extends ListActivity {

TallyDB db = new TallyDB(this);

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_saved_screen);

List<TallyCount> allTallyCounts = db.getAllTallyCounts();

int listSize = allTallyCounts.size();

String[] adapter = new String[listSize];

int i=0;

for (TallyCount tallyCount:allTallyCounts) {

tallyCount.getTally();

tallyCount.getTallyCount();

adapter[i++]=tallyCount.toString();

}

setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_saved_screen, R.id.txtTemplate, adapter));

}

}`

I'm not very good at this yet so forgive me if it's simple. I tried putting a second adapter and for loop to display the name but I must've done it wrong.

分享给朋友:
您可能感兴趣的文章:
随机阅读: