开发者

on checking one item in custom list view another get automatically selected?

Checking on one item in custom list view and another get selected in Android. I'm using custom adapter list view with check box.

I'm using check boxes in list view. and I'm using following code for check box count. i.e how many check box are selected.

final int listItemCount = screenList.getChildCount();
for (int i = 0; i < listItemCount; i++) {
    CheckBox cbox = (CheckBox) ((View) screenList.getChildAt(i))
     开发者_开发知识库       .findViewById(R.id.checkBox);
    if (cbox.isChecked()) {
        count++;
    }
}

But while I'm getting count=listItemCount there are some numbers are not shown checked in the list view.


In order to access the one you expect, do something like this (assuming you are using ListActivity:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    // this will give you the widget that was selected.
    Widget widget = widgetAdapter.getItem(position);

}

If this doesn't solve your problem, please show some code so we can take a look.


I'm having a similar problem with the list adapter. When the getview() is called for each customviewitem(has a checkbox) in the list the getview receives the position and the view object.

What i'm seeing while debugging is if the list shows 5 item at a time then say for 0th position the view obj id is 830173183032 then for the 6th position the view obj id is same ie 830173183032.

So when i check the checkbox of 0th item and then scroll down then I see that the 6th items checkbox also checked.

code was from http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜