tags:

views:

42

answers:

1

I am having a really difficult time trying to work with android's ListView multipleChoice mode. Here is what I am trying to do:

I have a "players" button in a game setup screen. When this is clicked it opens another activity with a multipleChoice ListView of all the players in the database in CheckedTextViews. I have this working properly and when you click on a player they will be added or removed from the game via a query to the game_players table.

The problem I am having is in setting up the ListView so that the players that have already been added to the game get checked initially when the activity opens.

I have tried to do this by iterating over the entire list in the ListView activity but this doesn't work because the Views that are not currently visible can't be accessed to check.

So now I'm trying to do this in my extended SimpleCursorAdapter in bindView but I can't even get this simple code to work:

@Override
public void bindView(View _view, Context _context, Cursor _cursor) {
    String name = c.getString(c.getColumnIndexOrThrow(from[0]));

    this.player = (CheckedTextView)_view.findViewById(to[0]);
    this.player.setText(name);
    this.player.setChecked(true);
}

It correctly sets the player's name with setText(), but I can't get any of the boxes to check in bindView. Is there somewhere else I should be doing this or am I just doing it incorrectly?

+1  A: 

Call setItemChecked() on the ListView for each checked position.

CommonsWare
Thank you! The loop I setup lastnight in onCreate for the list activity works great now.
Corbin Tarrant