之間的變量,這是我Manual.java文件:錯誤傳遞活動
public class Manual extends Activity implements OnClickListener{
Button create;
TextView gotAnswer, NoAnsV;
EditText NoQues, NoAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.manualask);
NoQues = (EditText) findViewById (R.id.NoQues);
NoAnswer = (EditText) findViewById (R.id.NoAnsw);
create = (Button) findViewById (R.id.create);
create.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.create:
Intent intent = new Intent(Manual.this, MCQSample.class);
Bundle b = new Bundle();
Integer Number = Integer.parseInt(NoQues.getText().toString());
intent.putExtras(b);
startActivity(intent);
finish();
break;
}
}
}
然後MCQSample.java:
public class MCQSample extends Activity{
TextView title;
String gotBread;
int value;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mcqsample);
title = (TextView) findViewById(R.id.abc);
Bundle b = getIntent().getExtras();
int value = b.getInt("key", 0);
title.setText(value);
}
}
然後mcqsample.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Text"
android:id="@+id/abc"/>
</LinearLayout>
兩個我已經添加到AndroidManifest中的類。
當我點擊Manual.java上的創建按鈕時,它總是崩潰。我的課有什麼問題?
呵呵TKS一堯字節。這一部分我已經完成了一整天! ~~。我剛剛學習Android –
歡迎您。快樂編碼:) – MByD
btw最後一個問題,我們如何傳遞數組而不是int?方式一樣嗎? –