[英]How can I transfer event from one child to another child if they are from same viewgroup in android?
So far I was able to transfer the event from the parent (viewgroup) to the child. 到目前为止,我已经能够将事件从父级(视图组)转移到子级。 ie When I click child 1, the viewgroup sends the event to child 1 and when I click child 2 (which is under child 1), the viewgroup sends the event to child 2.
即,当我单击子级1时,视图组将事件发送给子级1,而当我单击子级2(在子级1下)时,视图组将事件发送给子级2。
Problem : What I wanted to do was, When app is in certain state and child 2 is clicked I want the viewgroup to send the event to child 1 instead of child 2. 问题 :我想做的是,当应用程序处于特定状态并且单击了子级2时,我希望视图组将事件发送给子级1,而不是子级2。
So far : This link kind of touches the issue but is not in android. 到目前为止: 该链接有点触及问题,但不是在android中。
Something like this : In main viewgroup 像这样:在主视图组中
child2.setOnClickListener(new....{
and inside this event handler call an appropriate method in child1
child1.onSomethingInChild2()
What i did was inside dispatchTouchEvent of child 2 I test for the state. 我所做的是在孩子2的dispatchTouchEvent中测试状态。 If the the state is true I called child1.dispatchTouchEvent(event) and passed the event to child 1.
如果状态为true,则调用child1.dispatchTouchEvent(event)并将事件传递给子级1。
In child 2 在儿童2中
public boolean dispatchTouchEvent(MotionEvent event) {
if(cond == true){
child1.dispatchTouchEvent(event);
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.