读书人

一种关于ExpandableListView的长点击事

发布时间: 2012-07-01 13:15:00 作者: rapoo

一种关于ExpandableListView的长点击事件的实现

在使用ExpandableListView的时候,很多时候需要用到长点击事件。虽然ExpandableListView有个事件 OnChildClickListener,但是没有对应的OnChildLongClickListener。这个时候我们可以自己写一个用同种效果的 事件来代替OnChildLongClickListener()。
前提条件:在我们的Activity中已经有一个ExpandableListView对象,
private ExpandableListView expandableListView;
第一步:注册,给这个ExpandableListView对象注册一个Menu事件,
registerForContextMenu(expandableListView);
第二步:重写方法,重写onCreateContextMenu方法,
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
int type = ExpandableListView
.getPackedPositionType(info.packedPosition);
int group = ExpandableListView
.getPackedPositionGroup(info.packedPosition);
int child = ExpandableListView
.getPackedPositionChild(info.packedPosition);
if (type == 1)
{
Log.i(TAG,“长点击事件------在这里写任何长点击之后的处理代码”);
}

}

读书人网 >移动开发

热点推荐