Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable clicking on ListView in android?

I have a ListView that I'm populating with values from my database. If the database is empty, I'm setting the first item of the ListView to "No data.". I want to disable clicking on this item. I've used ArrayAdapter. I tried making areAllItemsEnabled,isEnabled false, but it was of no use. Even if I set the ListView's isClickable and setEnabled to false, it is of no use. And I put the code for the OnItemClickListener in the else condition,even that doesn't stop the list item from being clickable. Does someone have an alternate solution? Thanks!

like image 639
user1625971 Avatar asked Oct 30 '12 19:10

user1625971


People also ask

How do you stop a list item from responding to a user click?

view. setEnabled(false); Use this if you want to disable the listItem which user has clicked. Thus prevents the onclick event on that particular item.

How do I disable list view?

The general approach is to disable all the items instead of the whole view. Essentially: Inherit from ArrayAdapter (or any other adapter) Override isEnabled(int position) to return false.


1 Answers

In your custom ArrayAdapter use isEnabled function to return false:

@Override public boolean isEnabled(int position) {     return false; } 

always works for me.

like image 149
yahya Avatar answered Sep 29 '22 23:09

yahya