简体   繁体   English

为多个按钮实现OnTouchListener

[英]Implement OnTouchListener for multiple buttons

I implemented the OnTouchListener for my Layout including every layout/widget in it and I was successfully able to retrieve the direction of the swipe and the ID of the widget/layout that received the swipe. 我为自己的布局实现了OnTouchListener ,包括其中的每个layout/widget ,并且我能够成功检索到滑动的方向以及接收到滑动的widget/layout的ID。

My question is if the user swiped on two or more different objects, for example he swiped from left to right on two buttons, the first button receives the touch event and I get the id of that button only. 我的问题是,如果用户在两个或多个不同的对象上滑动(例如,他在两个按钮上从左向右滑动),则第一个按钮接收触摸事件,而我仅获得该按钮的ID。 how can I retrieve all the ids of the objects on which the swipe was made (same as the swipe keyboard functionality)? 如何获取在其上进行滑动的对象的所有ID(与滑动键盘功能相同)?

Is there a way to get the ID of every object that the user touched during his swipe movement by the X and Y of the touch event? 有没有一种方法可以通过触摸事件的X和Y来获取用户在其滑动运动期间所触摸的每个对象的ID?

Thanks. 谢谢。

If i understand your Problem currently then you can do like below. 如果我当前了解您的问题,则可以执行以下操作。

in OnTouch method of button use below code inside. 在按钮的OnTouch方法中使用下面的代码。

  LinearLayout mLinearlayout=(LinearLayout) v.getParent(); 

By this way you will get Button Parent View and now do process of getting Other View from Parent.Here i Use LinearLayout just for Example ,Because i have LinearLayout as parent of my Button View . 通过这种方式,您将获得Button父视图,现在执行从Parent那里获取其他视图的过程。这里我仅以LinearLayout为例,因为我将LinearLayout作为Button View父对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM