0

I have an activity that extends ListActivity, now I want to enable the click listener button in each row of the list. I did read some similar questions like this, but most of that extend from BaseAdapter to get the button. Actually, with the code below the button event was fired, however I have to double click on the row to fire the event.

    @Override
    // How can I trigger a single button instead of firing whole the row
protected void onListItemClick(ListView l, View v,final int position, long id) {

    super.onListItemClick(l, v, position, id);

    //removeTask(position);

    ImageView remove = (ImageView)v.findViewById(R.id.remove_task);

    remove.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            removeTask(position);
        }
    });
}

I hope my question makes sense. Thanks

Harry
  • 303
  • 1
  • 6
  • 22

1 Answers1

1

In order to get the click listener of button in each row of list view, you can add the setOnClickListener of button in getView() method of your custom adapter.

refer this link : Android: ListView elements with multiple clickable buttons

Community
  • 1
  • 1
Kri
  • 1,846
  • 2
  • 13
  • 17