ListView setOnItemClickListener not working by adding button

If you have an active view/focusable view in your list view then it will disable onItemClickListener... you can try to make it unfocusable by adding: android:focusable="false" to any view that is usually focusable.


Sometimes the List will still not be able to make the Click Listener to pass. And at this case you might have to add one more attribute.

android:descendantFocusability="blocksDescendants" 

And this attribute has to be added to the top most layout of your XML where you have provided the ListView elements.


Batter thing is to add both Listener to the whole of the rowView and to the Button inside Adapter. Something like this.

public class MyAdapter extends BaseAdapter implements View.OnClickListener{

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
            View rowView = convertView;
            if(rowView == null)
            {
                    //intialize rowView, and set onclick listener only once.
                    rowView = someIntilizationMehhodOrInflatorMethod();
                    //add listener to the button also and also to the row view
                    rowView.setOnClickListener(this);
            }
            //all your inflation and setting values goes here and at the end,
            //set position as tag to get the correct position, rather buggy one.
            rowView.setTag(String.valueOf(position));


            return rowView;
    }
    public void onClick(View v)
    {
            //now get the tag of View v and convert it to integer.
            int pos = Integer.parseInt(v.getTag().toString());
            Toast.makeText(context,"Item in position " + pos + " clicked",Toast.LENGTH_LONG).show();
    }
}

Try setting your buttons (or any other views you want to handle click inside a list item) like this:

android:focusable="false"
android:focusableInTouchMode="false"