【问题标题】:How to implement a listener for ExpandableListView release after a longItemClick [duplicate]如何在 longItemClick [重复] 后实现 ExpandableListView 发布的侦听器
【发布时间】:2023-04-09 18:41:01
【问题描述】:

在我的项目中,在OnLongClick 事件之后发布ExpandableListView 项目时,我需要执行一些操作。这个怎么做?谁能举个简单的例子?

【问题讨论】:

标签: android listview onclicklistener


【解决方案1】:
expandableListview.setOnItemLongClickListener(new OnItemLongClickListener() {
      @Override
      public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
          int itemType = ExpandableListView.getPackedPositionType(id);

          if ( itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
              childPosition = ExpandableListView.getPackedPositionChild(id);
              groupPosition = ExpandableListView.getPackedPositionGroup(id);

              //do your per-item callback here
              return true; //true if we consumed the click, false if not

          } else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
              groupPosition = ExpandableListView.getPackedPositionGroup(id);
              //do your per-group callback here
              return true; //true if we consumed the click, false if not

          } else {
              // null item; we don't consume the click
              return false;
          }
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 2015-12-11
    • 1970-01-01
    • 2020-09-16
    相关资源
    最近更新 更多