0

我想修改我的ExpandableListView,以便在正常单击时展开单击的组并折叠所有其他组,长按时仅展开单击的组。如果有,这将是非常微不足道的getOnClickListener()

OnClickListener oldListener = view.getOnClickListener(); // DOESN"T EXIST
view.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        collapseAll();
        oldListener.onClick(v);
    }
}
view.setOnLongClickListener(new OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        oldListener.onClick(v);
        return true;
    }
}

但是没有这样的方法。我可以通过 来做到这一点ExpandableListView.expandGroup(int position),但我需要从视图中找到位置,这使得它应该变得更加复杂。有更好的主意吗?

4

1 回答 1

0

You can cache the view position in the view itself by setting its position to its tag..

view.setTag(position);

You have to do this while adding the child views, probably in the adapter class..

Then when you need the position get it from the view itself by calling view.getTag();

于 2012-09-21T19:09:50.243 回答