How to disable clicking on ListView in android?

user1625971 picture user1625971 · Oct 30, 2012 · Viewed 35.2k times · Source

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!

Answer

yahya picture yahya · Oct 30, 2012

In your custom ArrayAdapter use isEnabled function to return false:

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

always works for me.