等待3秒或用户点击 [英] wait for 3 seconds or user click

查看:179
本文介绍了等待3秒或用户点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个情况下,我在等待一个小的一段时间例如3秒,继续前进。但是,如果用户点击我的屏幕上的按钮,然后继续前进,因为我无论如何都会。两个事件将触发相同的行为,即,更新在屏幕上的文本。有什么想法?

I am trying to set up a situation where I am waiting for a small period of time say 3 seconds and move on. But if the user clicks my on-screen button then move on as I would have anyway. Both events will trigger the same behaviour namely to update text on the screen. Any thoughts??

新到Android,但mclovin它

New to Android but mclovin' it

在此先感谢

推荐答案

尝试是这样的:

private Thread thread;    

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutxml);

    final MyActivity myActivity = this;   

    thread=  new Thread(){
        @Override
        public void run(){
            try {
                synchronized(this){
                    wait(3000);
                }
            }
            catch(InterruptedException ex){                    
            }

            // TODO              
        }
    };

    thread.start();        
}

@Override
public boolean onTouchEvent(MotionEvent evt)
{
    if(evt.getAction() == MotionEvent.ACTION_DOWN)
    {
        synchronized(thread){
            thread.notifyAll();
        }
    }
    return true;
}    

有等待3秒继续,但如果用户触摸屏幕上的螺纹被通知,并将其停止等待

It waits 3 seconds to continue but if the user touches the screen the thread is notified and it stops waiting.

这篇关于等待3秒或用户点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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