views:

41

answers:

1

Android ListView

if my list has 10 items.. the onclick listener is fired only for the 10th item. How to get the state of checkbox in a onListItemClick in Listactivity?

I have a class OnItemClickListener like this:

private class OnItemClickListener implements OnClickListener {
    private int mPosition;

    public OnItemClickListener(int position) {
        mPosition = position;
    }

    @Override
    public void onClick(View arg0) {
        if (arg0 == repeat_chbt) {//check box is checked 

                A

        } else {//item is checked

                B
        }
    }
}

and I use this class like this in my getview()

repeat_chbt.setOnClickListener(new OnItemClickListener(position));

but only when I check the last item's checkbox, it go A correctly. Other items' checkbox are checked they just go B. Who could tell me where I am wrong. Thanks very much. I've searched many site, but I didn't find out the answer.

A: 

If you are using android:choiceMode="multipleChoice", call isItemChecked() to see if any given position is checked.

CommonsWare
Thanks CommonsWare for your so soon answer very much.But I cant go that very well too.
AnothrWu
Hi CommonsWare, could you tell where I should put the android:choiceMode="multipleChoice" to? My <CheckBox>?or My <ListView>
AnothrWu
@AnothrWu: `ListView`, as you could have determined by clicking the link in my answer.
CommonsWare
I use instance to check which wiget come, Thank CommonsWare
AnothrWu