长按ExpandableListView中的选项

来源:互联网 发布:音乐后期软件 编辑:程序博客网 时间:2024/05/16 16:24

此乃同事编写

这个扩展ListView是仿QQ的

group--分组--好友分组
child--子项--friend


@Override
 public void onCreateContextMenu(ContextMenu menu, View v,
   ContextMenuInfo menuInfo) {
  super.onCreateContextMenu(menu, v, menuInfo);
  ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
  //menuinfo该对象提供了选中对象的附加信息
  
  int type = ExpandableListView
    .getPackedPositionType(info.packedPosition);
    
  int group = ExpandableListView
    .getPackedPositionGroup(info.packedPosition);
    
  int child = ExpandableListView
    .getPackedPositionChild(info.packedPosition);
    
  System.out.println("LongClickListener*type-------------------------"
    + type);
  System.out.println("LongClickListener*group-------------------------"
    + group);
  System.out.println("LongClickListener*child-------------------------"
    + child);
  this.setMGroupID(group);
  this.setMChildrenID(child);
  //响应
  if (type == 0) {// 分组长按事件
   showDialog(Globals.DIALOG_GROUPS_LONGCLICK);
  } else if (type == 1) {// 长按好友列表项
   showDialog(Globals.DIALOG_FRIENDlIST_LONGCLICK);
  }

 }

//一般在此函数下面编写响应事件
 @Override
 public boolean onContextItemSelected(MenuItem item) {
  return super.onContextItemSelected(item);
 }

 

 

原创粉丝点击