自定义 ListView:分隔符条目忽略设置
我创建了一个带有分隔符的自定义 ListView(使用此教程)。它看起来和工作都很好,但分隔符仍然是可点击的、可聚焦的,并且能够获取从中调用的上下文菜单。所以我试图“让他们闭嘴”:
...
case TYPE_SEPARATOR:
convertView.setFocusable(false);
convertView.setClickable(false);
convertView.setLongClickable(false);
break;
}
return convertView;
但他们完全忽略了这些设置!出于测试目的,我使用了 covertView.setBackground(Color.MAGENTA)
并且效果很好。有人知道可能出了什么问题吗?
I've created a custom ListView with separators (using this tutorial). It looks and works fine but the separators are still clickable, focusable and able to get a context menu called from. So i've tryied to "shut them up":
...
case TYPE_SEPARATOR:
convertView.setFocusable(false);
convertView.setClickable(false);
convertView.setLongClickable(false);
break;
}
return convertView;
But they totally ignore these settings! For testing purposes i used covertView.setBackground(Color.MAGENTA)
and it works well. Anyone got an idea what could be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的适配器是实现 BaseAdapter 的适配器(例如 ArrayAdapter),请覆盖 isEnabled() 方法。
要跟踪哪些项目是分隔符,哪些不是分隔符,请保留 ArrayList 或其他类型的跟踪集合。
Assuming your adapter is one that implements BaseAdapter (such as an ArrayAdapter), override the isEnabled() method in the adapter.
To keep track of which items are separators and which are not, keep an ArrayList or some other type of collection that keeps track.