我无法弄清楚如何将监听器附加到子元素,以便在用户点击电话号码时触发一些操作。
非常感谢任何代码或链接。
答案 0 :(得分:20)
getExpandableListView().setOnChildClickListener(this);
并实现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;
}
答案 1 :(得分:2)
您应该在可扩展列表中指定项目的位置,如此
listView.setOnChildClickListener(new OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView parent, View v, int group_position, int child_position, long id)
{
if(group_position==0 && child_position==0){
TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment);
secondFragment.getView().setVisibility(View.VISIBLE);
} else if(group_position==2 && child_position==2){
TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment);
secondFragment.getView().setVisibility(View.VISIBLE);
}
return false;
}
});
答案 2 :(得分:1)
您应该在ExpandableListActivity扩展程序中覆盖onChildClick。