ExpandableListView 长按事件

来源:互联网 发布:java 数组异或运算 编辑:程序博客网 时间:2024/04/30 04:29

ExpandableListView 中没有onGroupLongClickListener,也没有onChildLongClickListener,这就为我们自定义ExpandableListView 的长按事件增加了困难。
下面是我用OnItemLongClickListener写的一个自定义child的长按事件:

/** * OnLongClickListener */OnItemLongClickListener onItemLongClickListener = new OnItemLongClickListener() {public boolean onItemLongClick(AdapterView<?> parent, View childView,int flatPos, long id) {if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {long packedPos = ((ExpandableListView) parent).getExpandableListPosition(flatPos);final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);final int childPosition = ExpandableListView.getPackedPositionChild(packedPos);if(adapter.getChild(groupPosition, childPosition).equals("Empty")){Toast.makeText(getApplicationContext(), "It's empty.", 1).show();}else{AlertDialog.Builder dialog = new AlertDialog.Builder(secPlayBackActivity.this);dialog.setTitle("Delete this file?");dialog.setPositiveButton("Yes", new OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// delete checked fileString path = baseSpecphoneDir+ adapter.getGroup(groupPosition)+ "/"+ adapter.getChild(groupPosition, childPosition);upDirectory = baseSpecphoneDir+ adapter.getGroup(groupPosition);fileDelete(path);groupPos = groupPosition;}});dialog.setNegativeButton("Cancel", null);dialog.setCancelable(false);dialog.create().show();}return true;}return false;}};


0 0