What worked for me:
When inflating the title view before adding it to the list, I then used this view to get a subview and add a click listener to it
myHeaderView.findViewById(R.id.myButton).setOnClickListener(new OnClickListener() { ... } );
also, when I added it to listView, I used an overloaded constructor with the third variable set to true
mListView.addHeaderView(myHeaderView, null, true);
source share