2013-10-08 114 views
0

我想同时呼叫3个按钮或使用延迟时间。自动呼叫按钮

如何在上述某些时间自动调用按钮?

+0

问题是关于awt,gwt,swt ..... ??? – mKorbel

+0

我使用eclipse,所以它适用于swt?对? swt如何实现? – user2857609

+0

Eclipse使用SWT true,并不意味着在eclipse中使用SWT创建的项目:-) – Thihara

回答

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线程继续执行。

+0

好的,我试图..谢谢 – user2857609

+0

我试过这个,但给我的错误 它说“不能instatiate类型Runnable” – user2857609

+0

@ user2857609唉!抱歉花花公子,错字错误,我更新了代码,请试试 – 2013-10-08 12:13:39

0

只是使用Thread.sleep()调用其监听器的OnClick方法。并且不要忘记在新线程中分开它,以便UI线程继续执行使用Handler

+0

Button next =(Button)findViewById(R.id.button1); \t \t \t \t next.setOnClickListener(新View.OnClickListener(){ \t \t \t \t \t \t \t \t \t \t公共无效的onClick(查看视图){ \t \t \t \t \t \t意图myIntent =新 \t \t \t \t \t \t \t \t Intent(view.getContext(),ClassTwo.class); \t \t \t \t \t \t startActivityForResult(myIntent,0); \t \t \t \t \t} \t \t \t \t \t}); – user2857609

+0

谢谢约翰为改善答案:) – 2013-10-08 08:09:54