我想同时拨打3个按钮或使用延迟时间。
如何在一定时间内自动调用按钮?
答案 0 :(得分: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线程继续执行。
答案 1 :(得分:0)
使用Thread.sleep()调用他们的侦听器OnClick方法。并且不要忘记在新线程中将其分开,以便ui线程继续为此执行use Handler
。