1
我知道函數onCreate()用於構造活動和UI組件,但是當我嘗試在函數onStart()或onResume(),UI組件apper中放置setContentView(R.layout.activity_main)時,這就是爲什麼?在哪裏我把功能setContentView()?
package com.example.E001;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void onStart() {
super.onStart();
setContentView(R.layout.activity_main);
//setContentView(R.layout.demo);
Button btn_welcome = (Button)this.findViewById(R.id.welcome_msg);
btn_welcome.setText(R.string.hello_world);
}
}