我是android新手。只是玩基本的東西。這裏是我的代碼android動態創建文本視圖
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
setContentView(R.layout.activity_display_message);
// Get the message from the intent
Intent intent = getIntent();
String status = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(status);
textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
linearLayout.addView(textView);
}
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff99ccff"
android:orientation="vertical" >
</LinearLayout>
當我我的手機上運行這個它說, 「不幸的是,該應用程序已停止」
Post Logcat請 – Amsheer 2015-04-01 09:41:28
這部分代碼是錯誤的String status = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);顯示Logcat請 – Arlind 2015-04-01 09:53:50