0
中選中的單選按鈕打開一個新的活動我正在做一個項目在android.I'm仍然是Android應用程序開發的初學者。我有一個點擊按鈕,會根據單選按鈕檢查新的活動。我有5個單選按鈕,選擇一個並按下go按鈕後,它應該轉到新的活動。 問題是,在我的手機上加載應用程序時,單選按鈕正在工作,因爲它們顯示出來,當我點擊其中一個選項,但是當我單擊去時,什麼也沒有發生。代碼如下:基於Android
JAVA代碼的.java)
package com.example.android.travelindia;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
public class India extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_india);
this.finish();
final RadioButton beach = (RadioButton) findViewById(R.id.radio1);
final RadioButton hillstation = (RadioButton) findViewById(R.id.radio2);
final RadioButton wildlife = (RadioButton) findViewById(R.id.radio3);
final RadioButton historical = (RadioButton) findViewById(R.id.radio4);
final RadioButton reli = (RadioButton) findViewById(R.id.radio5);
final Button go = (Button) findViewById(R.id.button1);
go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (beach.isChecked()) {
Intent Intents= new Intent(India.this, sands.class); // <----- START "BEACHES" ACTIVITY
startActivity(Intents);
setContentView(R.layout.activity_sands);
}
else if (hillstation.isChecked()) {
Intent Intentm = new Intent(getApplicationContext(), mountains.class); // <----- START "HIll STATIONS" ACTIVITY
startActivityForResult(Intentm, 0);
}
else if (wildlife.isChecked()) {
Intent Intentw = new Intent(getApplicationContext(), forests.class); // <----- START "WILDLIFE" ACTIVITY
startActivityForResult(Intentw, 0);
}
else if (historical.isChecked()) {
Intent Intenth = new Intent(getApplicationContext(), history.class); // <----- START "HISTORICAL MONUMENTS" ACTIVITY
startActivityForResult(Intenth, 0);
}
else if (reli.isChecked()) {
Intent Intentr = new Intent(getApplicationContext(), religious.class); // <----- START "RELIGIOUS LOCATIONS" ACTIVITY
startActivityForResult(Intentr, 0);
}
}
});
}
}
爲什麼你有「this.finish()」和setContentView(R.layout.activity_sands)???刪除他們 – OShiffer
@OShiffer它的工作!謝謝! –