Can I make a ListView item not selectable?

冷暖自知 提交于 2019-12-03 11:31:29

问题


I am implementing an endless ListView (like in the Twitter app). I want to make the last item not selecteble. So that if the penultimate item is selected and I scroll down with my trackball, nothing happens. I tried setting android:focusable="false" and android:cickable="false" but I didn't notice any chnage.


回答1:


It's pretty easy, in your adapter you can override the method isEnabled(int position) and return false for this item.




回答2:


if you're using custom array adapter just override this method.

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



回答3:


If you want to get the same effect without having to have a custom adapter, you make the OnClickListener ignore that item when tapped and then set a solid background color for the item's view, so it doesn't highlight when tapped.



来源:https://stackoverflow.com/questions/5126581/can-i-make-a-listview-item-not-selectable

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