zoukankan      html  css  js  c++  java
  • ExpandableListView的OnitemLongclickListener事件

    expandableListView是带分组的Listview,通常会有setOnChildClickListener,setOnGroupClickListener,但如果是长按的事件,可以用以下方法来实现长按事件的监听

    elv.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);
                          Toast.makeText(getApplicationContext(), "childPosition"+childPosition+"groupPosition"+groupPosition, 0).show();
                          //do your per-item callback here
                          return true; //true if we consumed the click, false if not. consume : 消耗
    
                      } else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                          groupPosition = ExpandableListView.getPackedPositionGroup(id);
    
                          Toast.makeText(getApplicationContext(),"groupPosition"+groupPosition, 0).show();
                          //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;
                      }
              }});
  • 相关阅读:
    P4556 [Vani有约会]雨天的尾巴
    [模拟赛20180809] 旅程
    【jzoj3464】秀姿势
    【noip2013】火柴排队
    做运动
    【noip2013】花匠
    【noip2016】愤怒的小鸟
    【bzoj4326】【noip2015】运输计划
    作业二:个人编程项目——编写一个能自动生成小学四则运算题目的程序
    自我介绍
  • 原文地址:https://www.cnblogs.com/yiludugufei/p/4583463.html
Copyright © 2011-2022 走看看