05-27 17:00:28.636: WARN/System.err(17014): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.testButton.performClick();出错了,这句只能在主线程调用,在子线程中不可以使用。

解决方案 »

  1.   

    另外,我最终想解决的问题是这样的,Activity里有3个Button...我想在Activity显示一段时间后,自动触发一个Button,应该怎么写?onCreate,onStart,onResume里的都是在Activity显示之前就会click....求指教啊求指教...
      

  2.   

    关注 学习了
    如果不能在子线程里面做 就单独做一个Timer吧 用TimerTask处理就行了啊
      

  3.   

    新手,紧急搜索了下怎么用TimerTask,写了一个,发现没用...用Log.i可以输出log,但是performClick事件和Toast.makeText事件都没有反应...
    public class aaa extends Activity
    {
    private Button testButton;
    Timer tm = new Timer();
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    { super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    testButton = (Button) findViewById(R.id.Button01);
    testButton.setClickable(true);
    testButton.setOnClickListener(new Button.OnClickListener()
    {
    @Override
    public void onClick(View arg0)
    {
    testButton.setText("clicked!");
    }
    });

    Toast.makeText(aaa.this, "delay Over", Toast.LENGTH_LONG).show(); tm.schedule(new pressButton(), 5000);
    // testButton.performClick();
    } public class pressButton extends java.util.TimerTask
    {
    public void run()
    {
    Log.i("TimerTask","Success");
    Toast.makeText(aaa.this, "Timer task", Toast.LENGTH_LONG).show();
    testButton.performClick();
    }
    }
    private void delay(int i)
    {
    try
    {
    Thread.sleep(i * 1000);
    } catch (Exception e)
    {
    }
    }
    }
      

  4.   

    神啊,到底叫我如何才能performClick呢...
      

  5.   

    搞定了,虽然还是不能performClick,但是可以直接做onClickLisnter里的事情...谢谢vclongking和yyy025025025的指点...