Android的按键的KeyDown

Android的按键的KeyDown

本文介绍了Android的按键的KeyDown - 的KeyUp |不同的按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对devoloping Android应用一个简单的问题。
问题是指出错误类型的按钮。
例如,当我的按钮的手指,音乐播放,但是当我的手指高达按钮音乐停止。我怎样才能做到这一点。这也可能是不同势型按钮事件的,但我不知道。
我谷歌,但我发现任何东西。
PS:我可以开始,在普通按钮停止过程。但我做不到这样。
PS2:当我在论坛上搜索有人建议使用MotionEvent,但我想我的motionEvent codeS被打破

  play1.setOnClickListener(新View.OnClickListener()
{
    公共布尔onTouch(视图V,MotionEvent事件)
    {
        // TODO自动生成方法存根
        开关(event.getAction())
        {
            案例MotionEvent.ACTION_DOWN:
                 M1 = MediaPlayer.create(MainActivity.this,R.raw.be);
                m1.start();
                m1.setLooping(真);                打破;
            案例MotionEvent.ACTION_UP:
                m1.stop();
                m1.release();                打破;
            默认:
                打破;
        }
        返回false;


解决方案

好,好,我知道了。这就是我的回答。

  play1.setOnTouchListener(新View.OnTouchListener(){    @覆盖
    公共布尔onTouch(视图V,MotionEvent事件){
        INT eventaction = event.getAction();
        开关(eventaction){
            案例MotionEvent.ACTION_DOWN:                M1 = MediaPlayer.create(MainActivity.this,R.raw.be);
                m1.start();
                m1.setLooping(真);
            返回true;            案例MotionEvent.ACTION_UP:
           m1.stop();
           m1.release();            打破;
        }
        //告诉我们处理该事件,但需要进一步的处理系统
        返回false;    }
});

I have a easy question about devoloping android app.Question is diffrent type of button.For example, when my finger on the button, music is play but when my finger up to button music is stopped. How can i do this. İt's probably diffrent type of button event's but I don't know.I google ıt but I find anything.PS: I can starting, stopping process on normal button. But i can't do like this.PS2: When I search on forums somebody recommend to using MotionEvent but I guess my motionEvent codes are broken.

play1.setOnClickListener(new View.OnClickListener()
{
    public boolean onTouch(View v, MotionEvent event)
    {
        // TODO Auto-generated method stub
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:


                 m1=MediaPlayer.create(MainActivity.this, R.raw.be);
                m1.start();
                m1.setLooping(true);

                break;
            case MotionEvent.ACTION_UP:
                m1.stop();
                m1.release();

                break;
            default:
                break;
        }
        return false;
解决方案

Okay okay ı got it. This is my answer.

play1.setOnTouchListener(new View.OnTouchListener() {





    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int eventaction = event.getAction();
        switch (eventaction) {
            case MotionEvent.ACTION_DOWN:

                m1=MediaPlayer.create(MainActivity.this, R.raw.be);
                m1.start();
                m1.setLooping(true);
            return true;

            case MotionEvent.ACTION_UP:
           m1.stop();
           m1.release();

            break;
        }
        // tell the system that we handled the event but a further processing is required
        return false;

    }


});

这篇关于Android的按键的KeyDown - 的KeyUp |不同的按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:43