我已經找到了解決辦法:
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.row_child,
parent, false);
}
TextView textOne = (TextView) row
.findViewById(R.id.text_row_child1);
TextView textTwo = (TextView) row
.findViewById(R.id.text_row_child2);
HandleOnClick handleOnClick = new HandleOnClick (
groupPosition, childPosition, getChildId(groupPosition,
childPosition));
textOne.setOnClickListener(handleOnClick);
textTwo.setOnClickListener(handleOnClick);
return super.getChildView(groupPosition, childPosition,
isLastChild, row, parent);
}
private class HandleOnClick implements OnClickListener {
private int groupPosition;
private int childPosition;
private Long id;
public HandleOnClick (int groupPostion, int childPosition,
Long id) {
this.groupPosition = groupPostion;
this.childPosition = childPosition;
this.id = id;
}
public void onClick(View v) {
idChild = id;
switch (v.getId()) {
case R.id.text_row_child1:
break;
case R.id.text_row_child2:
//........
感謝
我一直在尋找了一段時間的解決方案。我喜歡你的方法,我可能會使用它,儘管在適配器中定義點擊監聽器感覺有點奇怪。從活動本身定義適配器會更好(可能是在擴展組的情況下)。感謝您的解決方案。 – manuel 2012-08-14 17:13:17