触发多个按钮(onClick事件)与一刷卡/手势 [英] Triggering multiple buttons(onClick event) with one swipe/gesture

查看:103
本文介绍了触发多个按钮(onClick事件)与一刷卡/手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总之,我所寻找的是 - 触发onclick事件多个按钮(意见),这是在刷卡的单刷

In short, what i am looking for is - Single swipe that triggers onClick event for multiple buttons(views) that was swiped over.

我刚开始开发我的第一个Android应用程序和我面临的一个问题大概是并不复杂,但因为我没有任何经验,我无法拼凑的解决方案。

I have just started developing my first android app and am facing a problem that probably isn't that complicated but as i don't have any experience i can't piece together the solution.

我'想实现在多个按钮的刷卡时被偷走了,他们将检测并触发onClick的功能。我已经看了看手势和扔没有任何成功。

I'am trying to implement a swipe over multiple buttons that would detect when they are being swiped over and trigger the onClick function. I have looked at Gestures and Flings without any success.

曾经试图在计算器上实现一些previous的相关解决方案:

have tried to implement some of previous related solutions on StackOverflow:

Android的 - 基本手势检测

<一个href=\"http://stackoverflow.com/questions/9181529/detect-fling-gesture-over-clickable-items/9182176#9182176\">Detect一扔手势在点击的项目

和是否有可能动态地绘制从按钮的中心正在刷过并且彼此相邻的线

And is it possible to dynamically draw a line from the centers of buttons that are being swiped over and are next to each other?

推荐答案

我一直在寻找一个解决方案,并最终使工作。所以,我将在这里回答,并希望这将有助于给别人。

I was looking for a solution, and finally made it work. So I will answer here and hope it will help to someone.

我有一个问题检测刷卡与多个按钮的布局,所以我覆盖的方法 setOnTouchListener 对每个按钮,调用 gesturedetector内。 onTouchEvent(事件)(和你想检测到的事件做什么)。

I had a problem detecting a swipe with a layout with multiple buttons, so I override the method setOnTouchListener for every button, calling inside gesturedetector.onTouchEvent(event) (and do what you want to do with the event detected).

显然,检测按钮点击事件,你只需要使用 setOnClickListener 方法。

Obviously, to detect the button click event you only have to use setOnClickListener method.

也许这是不最优雅的方式,使这项工作,但至少对我的工作。

Maybe it's no the most elegant way to make this work, but at least worked for me.

这篇关于触发多个按钮(onClick事件)与一刷卡/手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆