如何在可扩展列表中为儿童创建点击事件 [英] How to create on click event for children in Expandable list
本文介绍了如何在可扩展列表中为儿童创建点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
http:/ /developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList2.html
我无法想象了解如何将侦听器附加到子元素,以便在用户点击电话号码时触发一些操作。
任何代码或链接都将不胜感激。
解决方案
您需要订阅 setOnChildClickListener
getExpandableListView()。setOnChildClickListener(this);
并实现OnChildClickListener
@Override
public boolean onChildClick(ExpandableListView parent,View v,int groupPosition,
int childPosition,long id){
//使用groupPosition和childPosition找到当前适配器中的项
返回true;
}
I am playing around with this example. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList2.html
I cannot figure out how to attach a listener to the children elements so that I can trigger some action when the user taps on the phone number.
Any code or links would be greatly appreciated.
解决方案
You need to subscribe to setOnChildClickListener
getExpandableListView().setOnChildClickListener(this);
and implement OnChildClickListener
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
// use groupPosition and childPosition to locate the current item in the adapter
return true;
}
这篇关于如何在可扩展列表中为儿童创建点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文