Last active
December 12, 2015 05:19
-
-
Save daichan4649/4721090 to your computer and use it in GitHub Desktop.
ExpandableListView 長押し処理実装方法 (for Android)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ExpandableListView 長押し時処理実装方法 | |
// イベント発生順番 | |
// (1) OnItemLongClickListener#onItemLongClick | |
// (2) OnCreateContextMenuListener#onCreateContextMenu | |
expandableListView.setOnItemLongClickListener(new OnItemLongClickListener() { | |
@Override | |
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { | |
// 選択要素位置 | |
int groupPosition = ExpandableListView.getPackedPositionGroup(id); | |
int childPosition = ExpandableListView.getPackedPositionChild(id); | |
int packedPositionType = ExpandableListView.getPackedPositionType(id); | |
if (packedPositionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { | |
// group | |
} else if (packedPositionType == ExpandableListView.PACKED_POSITION_TYPE_CHILDP) { | |
// child | |
} | |
return false; | |
} | |
}); | |
expandableListView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { | |
@Override | |
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { | |
// 選択要素位置 | |
long packedPosition = ((ExpandableListContextMenuInfo) menuInfo).packedPosition; | |
int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition); | |
int childPosition = ExpandableListView.getPackedPositionChild(packedPosition); | |
int packedPositionType = ExpandableListView.getPackedPositionType(packedPosition); | |
if (packedPositionType == ExpandableListView.PACKED_POSITION_TYPE_GROUPD) { | |
// group | |
} else if (packedPositionType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { | |
// child | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考URL
http://stackoverflow.com/questions/2353074/android-long-click-on-the-child-views-of-a-expandablelistview