Android : How to set onClick event for Button in List item of ListView

android listview custom adapter onclick button
android listview button click position
android add item to listview on button click
clickable listview android
how to set onclick event on listview in android
image button in listview android
listview with button and textview in android
android listview onitemclicklistener get item

I want to add onClick event for buttons used in item of Listview. How can I give onClick event for buttons in List Item.

You can set the onClick event in your custom adapter's getView method.. check the link

Create Custom Listener on Button in ListItem (ListView) in Android, Create Custom Listener on Button in ListItem (ListView) in Android Hi friends, this is my first article on C# Corner, I am Ravi Sharma, an Android developer. @Override; public void onClick(View v) {; if (customListner ! This is the main function to provide a listener for the button of each item of the list  ListView only response on clicking row but Button will stop getting focus.When we add checkbox, imageview or button then some time Listview stop response on click – mukesh Oct 8 '15 at 19:50 Hi. Thanks for this solution.

Handling click events within AdapterView such as ListView and , As a quick fix, we could just define OnClickListener for the buttons in the Below is a screenshot of a ListView with a TextView and 2 Button views each row. <​LinearLayout xmlns:android=""  Typically an item of a ListView is clickable after you use the setOnItemClickListener() method to register OnItemClickListener to receive the item-click event. However, the item is not clickable if it contains a button. This is because the focus is on the button. It is not on the item.

Try This,

public View getView(final int position, View convertView,ViewGroup parent) 
   if(convertView == null)
        LayoutInflater inflater = getLayoutInflater();
        convertView  = (LinearLayout)inflater.inflate(R.layout.YOUR_LAYOUT, null);

   Button Button1= (Button)  convertView  .findViewById(;

   Button1.setOnClickListener(new OnClickListener() 
       public void onClick(View v) 
           // Your code that you want to execute on this button click


   return convertView ;

It may help you....

Click Button in ListView And Get Item Position, In each ListView item, I put a button inside so when user clicks on the button, the ListView; The position of the view in the list; The row id of the item that was clicked Let's say we set the click listener on a button in the getView function new OnClickListener() { @Override public void onClick(View v) { int  Quantity number of item change when scroll the listview. Implementing button in the listview is a little complex task. But you can do it smoothly if you follow proper method with the efficient code snippets. Getting the proper position of clicked button and set onclick event for button required some additional coding lines.

In your custom adapter inside getView method :

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Do things Here 

ListView and OnClick Items| Android Studio Tutorial (Beginners) HD , For Instance, on click of list item row we might need to update some UI elements activity and set this click listener to the views, so view event is triggered, we get a public ListAdapter(ArrayList<String> people, OnClickListener clickListener) Here the listView layout contains the two buttons and a lable. Android custom listview add onItemClickListener example. On android applications listview supports both type of click functions onclicklistener() and onItemClickListener() but a major difference between both of them is onclicklistener() function set click event on whole list view user can press on any element but only single task it will do

I assume you have defined custom adapter for your ListView.

If this is the case then you can assign onClickListener for your button inside the custom adapter's getView() method.

Handle multiple click listeners in a listView (Example), Android ListView item and button clickable , programming tip with clear method to register OnItemClickListener to receive the item-click event. to this attribute to avoid focusing on the button when the list is displayed. Then in the activity_main.xml file, you add a ListView. android:onClick="clickMe" > So you can create an interface for listening to this button click event. public interface BtnClickListener { public abstract void onBtnClick(int position); } Let your custom adapter receive it as input.

how to handle event click button of item on listview in android , I had a requirement for the project that the main layout displays a list of items and each list item also I have created create a ListView with 4 items , and used a custom and android:onClick=”Increment” into layout of our “-” and “+” buttons. Below is a screenshot of a ListView with a TextView and 2 Button views each row. So, there are 3 touchable(2 Buttons and the rest of the space in a row) views that will react to clicking events. This will be our sample. In order to let the rest of the space in a row respond to an event, we have set focusable property of the buttons to false.

Android ListView item and button clickable, Buttons in listview do not fire onclick event but if I click the line it does. is the setup for the event in the fragment // ListView Item Click Listener listView. The onItemClick listener responds to the click event of the row of the list, not the button. Set onclicklistener function on ExpandableListView android. Get Clicked selected item from expandablelistview in android using setOnChildClickListener.

Clickable ListView Items with Clickable Buttons - Anna Scott, This article is intended to make a custom listener on a button, that belongs to a list item. This article is another answer for the interview question “How to use an interface in Android?“. Now to discuss the code to understand how to make a custom listener.

  • Care to explain with some code you have done???
  • Post your code of custom lisview.
  • Also see…
  • I have wrote my solution in this link…
  • UI operations or listeners should not be done in the Adapter. If i want to get it to the calling activity. How do i do it?
  • Why make ListView focusable and Button not focusable? I mean what happens when we do this?
  • ListView only response on clicking row but Button will stop getting focus.When we add checkbox, imageview or button then some time Listview stop response on click
  • Hi. Thanks for this solution. And how to send the data back to the activity who contain the Listview? On more clear, how the adapter can send the click event on a row imageButtowm to the parent activity. (because I need the parent activity to react.
  • @Franck try using handler to send data back.
  • This worked perfectly, and must be the right answer. ListView focusable true, button focusable false. Thanks!
  • You must set only one ClickListener per convertView
  • But you will create OnClickListener object on every getView, that's not bad?
  • Here how to get the list item details like postion and all