我想知道是否有人知道这个问题的解决方案:我正在使用单选按钮在Android中创建调查问卷,我想知道是否有Android解决方案可以记住单击了哪些单选按钮。例如,我有一个注册和登录,而不是每个用户必须每次点击调查问卷,我怎样才能让Android记住以前提交的按钮。如果我能让Android记住每个用户提交内容,那将是理想的...任何帮助都将受到赞赏,因为我甚至不知道从哪里开始。
以下是我的调查问卷代码:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_system);
/*
* The random generator which generates the data inside each individual
* string randomly
*/
randomGenerator = new Random();
/*
* The data within each string
*/
resultsIf1 = new String[] {
"100% good job",
"well done" };
resultsIf2 = new String[] {
"unlucky",
"try again" };
/*
* Holding the data for the radio buttons from the xml file
*/
RadioGroup gender = (RadioGroup) findViewById(R.id.question1);
gender.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer1A:
ans1 = 1;
break;
case R.id.answer1B:
ans1 = 2;
break;
}
}
});
RadioGroup nutrition = (RadioGroup) findViewById(R.id.question2);
nutrition.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer2A:
ans2 = 1;
break;
case R.id.answer2B:
ans2 = 2;
break;
}
}
});
btnSubmitQuiz = (Button) findViewById(R.id.submit);
btnSubmitQuiz.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// result answer 1
if (ans1 == 1 && ans2 == 1) {
displayResult(getRandomResult());
}
// result answer 2
else {
displayResult(getRandomResult2());
}
}
/*
* displays the results once the submit button is pressed
*/
private void displayResult(String result) {
Intent i = new Intent("com.example.system.SHOWRESULT");
i.putExtra("unique_constant", result);
startActivity(i);
}
public String getRandomResult() {
return resultsIf1[randomGenerator.nextInt(resultsIf1.length)];
}
public String getRandomResult2() {
return resultsIf2[randomGenerator.nextInt(resultsIf2.length)];
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.system, menu);
return true;
}
}