Android ExpandableListView长组点击监听防止展开
我在 Android 应用程序中使用 ExpandableListView
,希望在用户长时间单击组元素时执行操作,因此我在 BaseExpandableListAdapter< 中定义了一个
OnLongClickListener
/代码> 扩展名。侦听器按方面工作,但子元素不再扩展。有什么想法吗?
public class ConnectionAdapter extends BaseExpandableListAdapter {
...
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
// convertView is a LinearLayout
convertView.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
// my action here
return true;
}
});
}
...
}
I use a ExpandableListView
in my Android application an want to perfrom an action if the user clicks long on the group element, so I defined a OnLongClickListener
in my BaseExpandableListAdapter
extention. The listener works as aspected but the child elements does not expand anymore. Any ideas?
public class ConnectionAdapter extends BaseExpandableListAdapter {
...
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
// convertView is a LinearLayout
convertView.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
// my action here
return true;
}
});
}
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在可扩展列表视图上设置 setOnItemLongClickListener。
ExpandableListView.PACKED_POSITION_TYPE_GROUP是一个组的id,将其更改为
ExpandableListView.PACKED_POSITION_TYPE_CHILD,您可以通过长按组子项进行操作。
像这样的东西:
You can set setOnItemLongClickListener on your expandablelistview.
ExpandableListView.PACKED_POSITION_TYPE_GROUP is the id of a group, change it to
ExpandableListView.PACKED_POSITION_TYPE_CHILD and you can manipulate with longclicks on group childs.
Something like that:
您的代码没有进一步处理任何其他“onClick”事件的原因是您在返回中传递了“true”。如果您指示事件已处理,操作系统将停止尝试进一步处理任何进一步的事件。要让它处理此事件并展开,那么您需要将返回更改为 false 而不是 true
The reason that your code is not further processing any other 'onClick' events is because you are passing a 'true' in your return. If you indicate that an event was handled, the OS stops attempting to further process any further events. To have it process THIS event, and also expand, then you need to change the return to false instead of true