0
如何获取我的简单单选按钮测验的值到新的XML布局页面。我不确定发生了什么事。当我点击按钮时,它强制关闭。获取RadioButton的值
TextView hasil;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnSubmit = (Button) findViewById(R.id.submit);
btnSubmit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
int score = 0;
if (((RadioButton)findViewById(R.id.radioButton1)).isChecked()) {score++;}
if (((RadioButton)findViewById(R.id.radioButton8)).isChecked()) {score++;}
if (((RadioButton)findViewById(R.id.radioButton11)).isChecked()) {score++;}
if (((RadioButton) findViewById(R.id.radioButton16)).isChecked()){score++;}
if (((RadioButton) findViewById(R.id.radioButton19)).isChecked()){score++;}
if (((RadioButton) findViewById(R.id.radioButton24)).isChecked()){score++;}
if (((RadioButton) findViewById(R.id.radioButton25)).isChecked()){score++;}
if (((RadioButton) findViewById(R.id.radioButton29)).isChecked()){score++;}
displayResult(score);
}
});
}
private void displayResult(int score) {
String message = "You scored " + score;
message += " out of 6";
message += "\nWell done!";
hasil.setText(message);
}
请在崩溃时发布logcat – Lal