我似乎不能鏈接頁面上的多個按鈕。 該頁面主要有標題,低於其鏈接到3個不同的主題 ,我曾嘗試代碼(我在此網站上發現)3個按鈕是:在Android上連接按鈕
package com.ICTrevisionapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class topicstoquiz extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.topics);}
public void onClick(View v) {
{
Button clickedButton = (Button) v;
setContentView(0);
switch(clickedButton.getId())
{
case R.id.button2:
setContentView(R.layout.topic1);
Intent myIntent = new Intent (v.getContext(),topicstotopicone.class);
startActivityForResult(myIntent, 0);
break;
case R.id.button3:
setContentView(R.layout.topic2);
break;
}
}
}
的情況下部分。
我也曾嘗試代碼:
Intent myIntent = new Intent (view.getContext(),topicstoquiz.class);
startActivityForResult(myIntent, 0);
但我只能似乎得到它鏈接到一個活動,只能從一個按鈕。
我可能這樣做完全錯誤,所以我怎樣才能將頁面上的每個按鈕鏈接到一個單獨的活動,以便我可以將它們鏈接到其他頁面。 (如果是有道理的)
林丟失,這會的onCreate我把這個? super.onCreate(savedInstanceState); 或 保護無效onCreate(Bundle savedInstanceState) 我還需要擺脫我在那裏的情況說明嗎? 感謝您的快速回復:) – Crazyfool 2012-01-16 20:32:15
方法onCreate。 super.onCreate ...就是超級通話。你會把你的setContentView調用後發佈的代碼的第一部分。 – bschultz 2012-01-16 20:36:37
是的,如果你按照我提出的方式去解決這個問題,你會擺脫這種情況。提供的樣品nifftyRich也會給你你正在尋找的結果。 – bschultz 2012-01-16 20:43:02