Aric Sprague
Aric Sprague

Reputation: 21

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.

Upvotes: 1

Views: 36

Answers (0)

Related Questions