我需要在(6秒)TextView4中的文本之后的第一个免费(setContentView(R.layout.activity_logo);)中加载。但是程序做错了。启动应用程序后,应用程序等待6秒钟,然后再构建setContentView(R.layout.activity_logo);并写入TextView4

为什么?
谢谢

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_logo);

    try {
        TimeUnit.SECONDS.sleep(6);
        TextView textview4 = (TextView) findViewById(R.id.textView4);
        textview4.setText("alalaalalalalalal");

    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

最佳答案

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_logo);
            Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                   TextView textview4 = (TextView) findViewById(R.id.textView4);
        textview4.setText("alalaalalalalalal");
            }
        }, 6000);
}

08-25 21:17