N Sharma
N Sharma

Reputation: 34477

How to detect on which row button in a listview user clicked

Hello I have a listview in which I am using custom adapter & cutom layout of rows. I have like imageview at the top then bottom of it one checkbox at left end and button on right end.

Now I want to apply checked listener on checkboxand click listener on button. Here is this I am doing

mybutton.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
       // TODO Auto-generated method stub

   }
});

satView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
   @Override
   public void onCheckedChanged(RadioGroup group, int checkedId) {
       if (isChecked){
           // perform logic
       }
   }
});

Question

So in a listview there would be checkbox and buttton in each row. How would I know user click on second or third etc row checkbox or button.

Thanks in advance.

Upvotes: 3

Views: 738

Answers (1)

Blaze Tama
Blaze Tama

Reputation: 10948

There is some ways to do this. My prefferred method is by adding setOnCheckedChangeListener to your checkbox's holder in your custom view class, in getView method.

You can use position parameter in the getView to get the current row position.

Upvotes: 2

Related Questions