android – 当用户按下按钮直到用户释放该按钮时,如何调用函数重复

android – 当用户按下按钮直到用户释放该按钮时,如何调用函数重复,第1张

概述在 android中, 如何在用户按下按钮之前重复调用某个功能,直到他/她释放该按钮? 我检查了clickListener和longclicklistener,但看起来他们并不像我想要的那样. 谢谢. 您可以使用OnTouchListener: public class MainActivity extends Activity implements OnTouchListener{ 在 android中,

如何在用户按下按钮之前重复调用某个功能,直到他/她释放该按钮?

我检查了clickListener和longclickListener,但看起来他们并不像我想要的那样.

谢谢.

解决方法 您可以使用OntouchListener:

public class MainActivity extends Activity implements OntouchListener{    private button button;    // ...    @OverrIDe    public voID onCreate(Bundle savedInstanceState)    {        // ...        button = (button) findVIEwByID(R.ID.button_ID);        button.setontouchListener(this);        // ...    }    // ...    @OverrIDe    public boolean ontouch(VIEw v,MotionEvent event)    {        /* get a reference to the button that is being touched */        button b = (button) v;        /* get the action of the touch event */        int action = event.getAction();        if(action == MotionEvent.ACTION_DOWN)        {            /*                A pressed gesture has started,the motion contains                the initial starting location.            */        }        else if(action == MotionEvent.ACTION_UP)        {            /*                A pressed gesture has finished,the motion contains                the final release location as well as any intermediate                points since the last down or move event.            */        }        else if(action == MotionEvent.ACTION_MOVE)        {            /*                A change has happened during a press gesture (between                ACTION_DOWN and ACTION_UP). The motion contains the                most recent point,as well as any intermediate points                since the last down or move event.            */        }        else if(action == MotionEvent.ACTION_CANCEL)        {            /*                The current gesture has been aborted. You will not                receive any more points in it. You should treat this                as an up event,but not perform any action that you                normally would.            */        }    }}
总结

以上是内存溢出为你收集整理的android – 当用户按下按钮直到用户释放该按钮时,如何调用函数重复全部内容,希望文章能够帮你解决android – 当用户按下按钮直到用户释放该按钮时,如何调用函数重复所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1126571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存