单选按钮只显示第一个选项正确,其他显示Android的所有错误数据 [英] radio buttons showing only first option correct and the others showing all wrong data in android
问题描述
在我的问题的答案的小游戏我显示从数据库文件中的问题和答案。
问题是,在文本视图和答案都在radiobuttons.no数据显示精确我想要的方式,但当我选择数据只有单选按钮的第一个选项是选择是正确ansnwer只有当它是正确的answer.my在mainactivity code是如下`showQuestion =(的TextView)findViewById(R.id.tvQuestions);
showAnswer =(的TextView)findViewById(R.id.tvShowAnswer);
In my questions answers small game i am showing questions and answers from the database file. question is in text view and answers are in radiobuttons.no the data is showing accurately the way i wanted but when i am selecting the data only the first option of the radio button is selecting as correct ansnwer only if it is the correct answer.my code in mainactivity is as follows `showQuestion = (TextView) findViewById(R.id.tvQuestions); showAnswer = (TextView) findViewById(R.id.tvShowAnswer);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
r0 = (RadioButton) findViewById(R.id.radio0);
r1 = (RadioButton) findViewById(R.id.radio1);
r2 = (RadioButton) findViewById(R.id.radio2);
r3 = (RadioButton) findViewById(R.id.radio3);
bsubmit = (Button) findViewById(R.id.bsubmit);
bsubmit.setOnClickListener(this);
String shoow = myDb.makeatext(levels, Qno);
String showextra1 = myDb.makeExtra1(levels, Qno);
String showextra2 = myDb.makeExtra2(levels, Qno);
String showextra3 = myDb.makeExtra3(levels, Qno);
String showextra4 = myDb.makeExtra4(levels, Qno);
// String showextra4 =myDb.makeanswers(levels, Qno);
showQuestion.setText(shoow);
r0.setText(showextra1);
r1.setText(showextra2);
r2.setText(showextra3);
r3.setText(showextra4);
和在onclick()方法试图检查数据,但它是仅示出第一个单选按钮的答案正确的,如果该数据是正确的唯一
and in the onclick() method trying to check the data but it is showing only first radio button answer as correct if the data is correct only.
public void onClick(View v) {
strat = System.currentTimeMillis();
data = myDb.makeanswers(levels, Qno);
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bsubmit:
if (r0.isChecked() == true)
{
if (r0.getText().toString().equalsIgnoreCase(data)) {
showAnswer.setText("your answer is correct:" +r0.getText());
} else {
showAnswer.setText("your answer is wrong.the answer is:"
+ data);
}
}
if (r1.isChecked() == true)
{
if (r1.getText().toString().equalsIgnoreCase(data)) {
showAnswer.setText("your answer is correct:" + r1.getText());
} else {
showAnswer.setText("your answer is wrong.the answer is:"
+ data);
}
}
if (r2.isChecked() == true)
{
if (r2.getText().toString().equalsIgnoreCase(data)) {
showAnswer.setText("your answer is correct:" + r2.getText());
} else {
showAnswer.setText("your answer is wrong.the answer is:"
+ data);
}
}
if (r3.isChecked() == true)
{
if (r3.getText().toString().equalsIgnoreCase(data)) {
showAnswer.setText("your answer is correct:" + r3.getText());
} else {
showAnswer.setText("your answer is wrong.the answer is:"
+ data);
}
}}}
PLZ帮我出这我是新来的Andr ?? oid。它会是一个很大的帮助。
plz help me out of it i am new to the android .it will be a great help
谢谢,
马迪。
thanks, maddy.
推荐答案
请试着做这样的
case R.id.save_profile:
if(((RadioButton)findViewById(R.id.radio0)).isChecked()){
Answer=(RadioButton)findViewById(R.id.radio0)).getText().toString();
}
if(((RadioButton)findViewById(R.id.radio1)).isChecked()){
Answer=(RadioButton)findViewById(R.id.radio0)).getText().toString();
}
// compare here your option......
break;
之后,你需要比较检查按钮答案。
after that you need to compare the answer with checked button.
这篇关于单选按钮只显示第一个选项正确,其他显示Android的所有错误数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!