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!
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.
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.
In your custom ArrayAdapter use isEnabled function to return false:
@Override public boolean isEnabled(int position) { return false; }
always works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With