等待3秒或用户点击用户

由网友(Raccon浣熊)分享简介:我想建立一个情况下,我在等待一个小的一段时间例如3秒,继续前进。但是,如果用户点击我的屏幕上的按钮,然后继续前进,因为我无论如何都会。两个事件将触发相同的行为,即,更新在屏幕上的文本。有什么想法?I am trying to set up a situation where I am waiting for a sm...

我想建立一个情况下,我在等待一个小的一段时间例如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.

阅读全文

相关推荐

最新文章