我正在为我的xml开发一个quiz.in的应用程序我有一个问题,4个选项(选项是textviews)以及上一个和下一个按钮。我做了上一个和下一个按钮。但我面临选择的问题。当我单击或选择一个问题的选项时,所有问题选项也会选择。如何控制这种行为?请任何人帮忙怎么做?
if (v == rb1) {
Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show();
// quelay.setVisibility(View.INVISIBLE);
// answer.setVisibility(View.VISIBLE);
db.updateContact(question.getText().toString());
setNext();
if (v == rb2) {
Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show();
// quelay.setVisibility(View.INVISIBLE);
// answer.setVisibility(View.VISIBLE);
db.updateContact(question.getText().toString());
setNext();
答案 0 :(得分:0)
你可以试试这个。
private View.OnClickListener mCorkyListener = new View.OnClickListener() {
public void onClick(View v) {
// do something when the button is clicked
// Yes we will handle click here but which button clicked??? We don't know
// So we will make
switch (v.getId() /*to get clicked view id**/) {
case R.id.rb1:
Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show();
//quelay.setVisibility(View.INVISIBLE);
//answer.setVisibility(View.VISIBLE);
db.updateContact(question.getText().toString());
setNext();
break;
case R.id.rb2:
Toast.makeText(getApplicationContext(), rb2.getText().toString(), Toast.LENGTH_SHORT).show();
//quelay.setVisibility(View.INVISIBLE);
//answer.setVisibility(View.VISIBLE);
db.updateContact(question.getText().toString());
setNext();
break;
case R.id.rb3:
Toast.makeText(getApplicationContext(), rb3.getText().toString(), Toast.LENGTH_SHORT).show();
//quelay.setVisibility(View.INVISIBLE);
//answer.setVisibility(View.VISIBLE);
db.updateContact(question.getText().toString());
setNext();
break;
case R.id.rb4:
Toast.makeText(getApplicationContext(), rb4.getText().toString(), Toast.LENGTH_SHORT).show();
//quelay.setVisibility(View.INVISIBLE);
//answer.setVisibility(View.VISIBLE);
db.updateContact(question.getText().toString());
setNext();
break;
default:
break;
}
}
};
答案 1 :(得分:0)
试试这个,
ng-model="n.checked"
在两个条件中都显示 rb1.getText()。toString()。所以改变你的第二个条件部分,如
if (v == rb1) {
Toast.makeText(getApplicationContext(), rb1.getText().toString(), Toast.LENGTH_SHORT).show();
db.updateContact(question.getText().toString());
setNext();
if (v == rb2) {
Toast.makeText(getApplicationContext(), rb2.getText().toString(), Toast.LENGTH_SHORT).show();
db.updateContact(question.getText().toString());
setNext();