简体   繁体   English

如果事件来自Android中的同一视图组,如何将事件从一个孩子转移到另一个孩子?

[英]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.

相关问题 如何将单击事件从父(ViewGroup)委托给子(View)android? - How to delegate click event from parent (ViewGroup) to child (View) android? 如何使用startChildActivity将数据从一个子活动传输到另一个子活动? - how to transfer data from one child activity to another using startChildActivity? 在Android的“视图组”中设置孩子的样式? - Set child's style from the Viewgroup in Android? 除了一个特定的孩子之外,从过渡中排除 ViewGroup - Exclude ViewGroup from transition except one specific child 如何在Android中将Firebase子项从一个节点移动到另一个节点? - How to move Firebase child from one node to another in Android? 如何将视图从一个 ViewGroup 移动到另一个 - How to move a View from one ViewGroup to another 如何在Android中将数据从一项活动转移到另一项活动? - How do I transfer data from one activity to another in Android? 如何让一个android ViewGroup及其所有子视图根据最宽的子动态动态保持相等的宽度? - How can I make an android ViewGroup and all its child Views dynamically maintain equal width based on the widest child? 如何将数据从一个片段传输到另一个片段android - How can I transfer data from one fragment to another fragment android Android - 如何将ImageView从一个活动转移到另一个活动? - Android - how can i transfer ImageView from one activity to another activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM