标识已在expandableListView中单击的组 [英] Identifying the group that has been clicked in an expandableListView

查看:71
本文介绍了标识已在expandableListView中单击的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定已在expandableListView中单击的视图.当我设置一个OnItemLongClickListener时,我得到一个参数,该参数显示单击的视图在列表中的位置.但是,它也计算子视图.我希望它只计算组,所以当单击一个组时,我可以确定它是哪个组.有办法吗?

I'm trying to identify a view that has been clicked in an expandableListView. When I set an OnItemLongClickListener I get an argument that shows me the position of the clicked view inside the list. However, it also counts child views. I'd like it to count only groups, so when a group was clicked I can determine which one it was. Is there a way to do that?

推荐答案

否,long参数不是打包值,这是适配器(getCombinedChildId())生成的ID.即使您以某种方式生成ID,尝试对其进行解释也是一个坏主意. ID是ID.

No, the long parameter is not the packed value, this is the ID generated by your adapter (getCombinedChildId()). Attempting to interpret an ID, even if you generate it in a certain way would be a bad idea. Id is an id.

我相信正确的方法是使用ExpandableListView.getExpandableListPosition(flatPos)方法.实际上,传递给侦听器的"pos"参数是固定列表位置. getExpandableListPosition()方法返回打包的位置,然后可以使用ExpandableListView的静态方法将打包的位置解码为单独的组和子位置.

I believe the right way is to use ExpandableListView.getExpandableListPosition(flatPos) method. Your "pos" argument passed to the listener is, in fact, flat list position. getExpandableListPosition() method returns the packed position which can be then decoded into separate group and child positions using the static methods of ExpandableListView.

我今天自己遇到了这个问题,所以我在描述我找到的对我有用的解决方案.

I have hit this problem myself today so I am describing the solution I have found working for me.

这篇关于标识已在expandableListView中单击的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆