Non-clickable Listview Item with Visible Divider

半世苍凉 提交于 2019-12-07 16:45:56

问题


I would like to disable clicking of a Listview item. One solution is to override areAllItemsEnabled() to always return false, and isEnabled() to return false for a particular position. However, this causes the divider lines around the particular Listview item to disappear. A few people suggested returning true for areAllItemsEnabled() and false for isEnabled(), but this is not working for me. I am hesitant to place a divider line in manually because I would need to add a parent layout to the item XML.

Is there a way to set a Listview item to be non-clickable and still retain


回答1:


The solution is exactly the opposite of what you were told to do. You should return false in areAllItemsEnabled() and just delete your override of isEnabled(). It works perfectly for me and I was also struggling with that issue yesterday.

All items will not be clickable since areAllItemsEnabled() == false but the divider will appear.




回答2:


I also had this issue, but overwriting these Adapter methods seemed ugly. Then one post struck me with an idea, that had worked before already. On the view that shouldn't be clickable just call view.setOnClickListener(null).

Boom, maybe this is a workaround rather than a real solution, but it works. I have to note that I added dividers programmatically to the ListView footer, so I had the reference to the dividers and I could simply set the OnClickListener to null.




回答3:


On the individual View, trying setting it to not be clickable: view.setClickable(false). If that doesn't work, try view.setFocusable(false).



来源:https://stackoverflow.com/questions/10657892/non-clickable-listview-item-with-visible-divider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!