0

我想同时调用 3 个按钮或使用延迟时间。

如何像上面那样在特定时间自动调用按钮?

4

2 回答 2

1

像这样的东西?!

public boolean onOptionsItemSelected(MenuItem item) {
        Log.i(TAG, "Menu Item selected " + item);
        if (item == button1) {
            variabel.setViewMode(ClassOne.Object1);
    new Thread(new Runnable(){
    public void run(){try{Thread.sleep(5000);onOptionsItemSelected(button3);}catch(Exception ex){}}
    }).start();
        } else if (item == button2) {
            variabel.setViewMode(ClassOne.Object2);
        } else if (item == button3) {
            variabel.setViewMode(ClassOne.Object3);
            new Thread(new Runnable(){
    public void run(){try{Thread.sleep(5000);onOptionsItemSelected(button2);}catch(Exception ex){}}
    }).start();
        }

尝试将这一切移动到新线程中,以便 ui 线程继续执行。

于 2013-10-08T08:01:59.320 回答
0

只需使用 Thread.sleep() 调用他们的侦听器 OnClick 方法。并且不要忘记在新线程中将其分开,以便 ui 线程继续为此执行使用Handler

于 2013-10-08T08:03:41.473 回答