[英]How to handle events clicks of different views within a row of a ExpandableListView child
I know how to handle the events by subscribing (setOnClickChildListener) of the ExpandableListView (or overriding the ExpandableListActivity callback method: onChildClick). 我知道如何通过订阅ExpandableListView(或覆盖ExpandableListActivity回调方法:onChildClick)订阅(setOnClickChildListener)来处理事件。 The two let me know the details groupPosition, childPosition and the view of the row layout (my custom layout for the childs).
这两个让我知道详细信息groupPosition,childPosition和行布局的视图(我的孩子的自定义布局)。 But I want to know what particular view has been clicked (for example which textview of my custom row).
但我想知道点击了哪个特定视图(例如我的自定义行的哪个textview)。
I tried it overriding the getView method of the mSimpleCursorTreeAdapter and subscribing my textviews to the onClick listener. 我尝试覆盖mSimpleCursorTreeAdapter的getView方法并将我的textviews订阅到onClick监听器。 But in this way I can't know the groupPosition and the childPosition of the child row clicked.
但是这样我就无法知道groupPosition和子行的childPosition被点击了。 If I handle the onClick of the views in this way, the event is consumed and OnClickChildListener and the callback method onChildClick never will be dispatched.
如果我以这种方式处理视图的onClick,则会消耗该事件,并且将永远不会调度OnClickChildListener和onChildClick的回调方法。
I guess I am saying something wrong. 我想我说错了。 I hope someone tells me a way to do.
我希望有人告诉我一个方法。
Thank you. 谢谢。
I've found a solution: 我找到了一个解决方案:
@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:
//........
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.