I have a ListView
that uses a customized adapter, but I can\'t click on the ListView Item ..
Activity for list view ..
package com.adham
I was using a view and button inside the list view so I have used:
android:focusable="false"
for <button>
and <view>
...
After that I used following code for my list view and it worked
// Attach the adapter to a ListView
ListView listView = (ListView) findViewById(R.id.shipping_item_list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(listPairedClickItem);
private AdapterView.OnItemClickListener listPairedClickItem = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getBaseContext(), "Item ", Toast.LENGTH_LONG).show();
}
};
I wanted to add a comment to rupps answer, but I do not have enough reputation.
If you are using a custom adapter extending the ArrayAdapter you can overwrite with areAllItemsEnabled() and isEnabled(int position) in your class:
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public boolean isEnabled(int position) {
return true;
}
The above fixed my non clickable list view. Maybe this comment also helps others as "android list not clickable" search term is quite high in Google.
I'm pretty late but discovered something I think it's interesting about this:
if your adapter descends from ArrayAdapter, as much as I have tried, onItemClickListener is not called.
However, if your adapter descends from BaseAdapter (so you have to implement getCount() and getItem(), trivial for an array) it IS always called.
List view items are clickable. To use it, you have to set item click listener on your list view. Then it will work.
try this to get the focus: View.getFocus();
For me, the problem was that my items within my ListView had clickable
set to true
.