I’m adding a footer and header view to a ListView by using the methods setHeaderView() and setFooterView() and a ViewInflater. That works quite well.
But how could I prevent the header or footer view from firing onListItemClick events? Of course I can catch the event and check whether it came from a header or footer, but this only solves one part of the problem, as header and footer got still focused when clicked.
Simply use the ListView#addHeaderView(View v, Object data, boolean isSelectable);
and matching
addFooter()method.The purpose of
Object dataparameter.The ListView source code describes the
dataparameter as:Which means if I use
listView.getAdapter().getItem(0);it will return thedataObject from our header.I’ll elaborate this with an example:
Next let’s add a header and set the adapter:
Later if we ask: