ListActivities setItemChecked in onListItemClick not working
I have this code here:
@Override
protected void onListItemClick(ListView l, View v, int posi开发者_StackOverflowtion, long id) {
super.onListItemClick(l, v, position, id);
if(l.isItemChecked(position))
l.setItemChecked(position, false);
else
l.setItemChecked(position, true);
Toast.makeText(mContext, "Mission: " + ((TreeNode)l.getItemAtPosition(position)).getTitle(), Toast.LENGTH_LONG).show();
}
It works as far as the debugger goes, but the setItemChecked never seems to really set the item both graphically I do not see the check box appear and then on the next click through the isItemChecked still returns false.
Not sure what I am doing wrong here?
just try this..... make android:focusable="false" to check box
have you tried refreshing the adapter of the list ?
l.getAdapter().notifyDataSetChanged();
If you set your ListView Adapter
to CHOICE_MODE_MULTIPLE
and you View with checkBox would implement Checkable
interface, you wouldn't need to handle toggling checkbox by yourself
精彩评论