如何禁用点击的ListView的机器人?机器人、ListView

2023-09-05 05:29:42 作者:挽歌°

我有我填充从我的数据库值一个ListView。如果数据库是空的,我设置的ListView的第一个项目为无数据。我想禁用这个项目点击。我用ArrayAdapter。我试图使areAllItemsEnabled,IsEnabled的假的,但它是没有用的。即使我设置ListView的isClickable和向的setEnabled虚假的,它是没有用的。我把code在其他条件OnItemClickListener,甚至不被点击阻止列表项。是否有人有一个替代的解决方案?谢谢!

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!

推荐答案

在自定义ArrayAdapter使用IsEnabled的函数返回false:

In your custom ArrayAdapter use isEnabled function to return false:

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

总是对我的作品。

always works for me.