My custom ListView
is not clickable. I am using setOnItemClickListener
. My ListView
row contains a button, image view and some textviews. Please help me make the items clickable.
Asked
Active
Viewed 400 times
1

Vatev
- 7,493
- 1
- 32
- 39

Jose Kurian
- 703
- 7
- 10
-
4add some code snippet. – Feb 25 '14 at 11:53
-
try to find solution on web, check this answer http://stackoverflow.com/a/12813906/1168654 – Dhaval Parmar Feb 25 '14 at 11:54
-
set `android:focusable="false"` for all `View`s in your custom `ListView` item layout... – Gopal Gopi Feb 25 '14 at 12:05
2 Answers
0
set clickable=false to all clickable views in listview row like (button).

Brijesh Patel
- 676
- 1
- 5
- 13
0
in case if you use controls like ImageButton
, CheckBox
,Button
etc then you would face problems discussed here and here.
This is simply because such controls can steal focus from the ListView
and the complete list item cant be selected/clicked.
I am assuming that you are using an Adapter to set the content of your list. Inside that adapter you can assign onClickListener()
s for each item like this:
public class MyListAdapter extends ArrayAdapter<String>{
.......
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView=inflator.inflate(R.layout.list_item, null, true);
ImageView image=(ImageView) rowView.findViewById(R.id.image1);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do something
}
}
Button button=(ImageView) rowView.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do something
}
}
.......
}
}
but remember that while using controls like ImageButton
, CheckBox
,Button
you need to assign property android:focusable="false"
in the XML. and for the ImageButton
you need to do this inside the getView()
method:
final ImageButton imgBtn=(ImageButton) rowView.findViewById(R.id.imgBtn);
imgBtn.setFocusable(false);
imgBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do your task here
}
});
Hope I answered your question.