Reputation: 1051
How to make the items in a list view not click able. i got topics and items in a list view but the view is same for both topics and items. the items are click able but the topic is not click able. how to achieve this
the list will look like
Topic
item
Topic
item
item
topic. click able(false) did not work, please help
Upvotes: 36
Views: 32444
Reputation: 11
In your ListView
add the following attribute
android:cacheColorHint = "#00000000"
Upvotes: 1
Reputation: 89
Set listSelector transparent in ListView
android:listSelector="@android:color/transparent"
Upvotes: 5
Reputation: 95
In your adapter, you have that put this:
view = inflator.inflate(R.layout.items_menu_header, null);
view.setOnClickListener(null);
I use a boolean to identify if header or item, so I assign a different layout for each type.
Upvotes: 1
Reputation: 16319
This is the correct answer:
I've found a lot of comments saying that
setEnabled(false)
setClickable(false)
setFocusable(false)
would work, but the answer is NO
The only workaround for this approach is doing:
view = inflater.inflate(R.layout.row_storage_divider, parent, false);
view.setOnClickListener(null);
Upvotes: 8
Reputation: 35991
Sharing my experience, the following did the trick (view refers to the list item view):
view.setEnabled(false);
view.setOnClickListener(null);
Upvotes: 58
Reputation: 3893
To make the items in a list non-clickable, you have to make the adapter return false on its isEnabled
method for the items in the list. An easy way to instantiate an adapter and override isEnabled
can be done in the following way:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, from, to, 0) {
@Override
public boolean isEnabled(int position) {
return false;
}
};
Upvotes: 19
Reputation: 7810
Don't know if you still need it, but you can implement your own Adapter and override the method isEnabled(int position). Depending on the ViewType of the item you will return true or false.
Upvotes: 72