开发者

ListActivities setItemChecked in onListItemClick not working

开发者 https://www.devze.com 2023-01-30 18:56 出处:网络
I have this code here: @Override protected void onListItemClick(ListView l, View v, int posi开发者_StackOverflowtion, long id) {

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

0

精彩评论

暂无评论...
验证码 换一张
取 消