possible duplicates
ListView OnItemClickListener Not Responding?
OnItemClickListener and OnClickListener not working for ListView
I have added onClickListener
to root layout of list item and according to the answer to above question and this post I made same root layout focusable=false
. Tried from both, java as well as xml.
But still no luck, OnItemClickListener
is not responding to item click events.
please have a look at following code,
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/todoly_selector_list_item">
[..Some code..]
</RelativeLayout>
and the getView
of adapter has following code,
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
/*
* I need to have this, if I remove this line OnItemClickListener works,
* no otherwise.
*/
convertView.setOnClickListener(onClickListener);
convertView.setFocusable(false);
[..Some code..]
}
What I am doing wrong here? or Is it not possible to do so?