gpt4 book ai didi

java - 不知道将该代码放在我的 java 文件中的哪里

转载 作者:行者123 更新时间:2023-12-02 06:16:18 28 4
gpt4 key购买 nike

我很困惑将该代码放在哪里,以便用户在选择单选按钮之前不会转到其他页面。

这是我不知道该放的代码:

if(rda.isChecked() == true)
{
butNext.setEnabled(true);
}

if(rdb.isChecked() == true)
{
butNext.setEnabled(true);
}

if(rdc.isChecked() == true)
{
butNext.setEnabled(true);
}
else
{
butNext.setEnabled(false);
}

这是我的整个代码或MainAct.java:

List<Question> quesList;
int score=0;
int qid=0;
Question currentQ;
TextView txtQuestion;
RadioButton rda, rdb, rdc;
Button butNext;
RadioGroup radioGroup1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
DBase db=new DBase(this);
quesList=db.getAllQuestions();
currentQ=quesList.get(qid);
txtQuestion=(TextView)findViewById(R.id.textView1);
rda=(RadioButton)findViewById(R.id.rda);
rdb=(RadioButton)findViewById(R.id.rdb);
rdc=(RadioButton)findViewById(R.id.rdc);
butNext=(Button)findViewById(R.id.button1);
setQuestionView();
butNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
RadioGroup grp=(RadioGroup)findViewById(R.id.radioGroup1);
RadioButton answer=(RadioButton)findViewById(grp.getCheckedRadioButtonId());
Log.d("yourans", currentQ.getANSWER()+" "+answer.getText());

if(currentQ.getANSWER().equals(answer.getText()))
{
score++;
Log.d("score", "Your score"+score);
}
if(qid<10)
{
currentQ=quesList.get(qid);
setQuestionView();
}
else
{
Intent intent = new Intent(MainAct.this, activity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

private void setQuestionView()
{
txtQuestion.setText(currentQ.getQUESTION());
rda.setText(currentQ.getOPTA());
rdb.setText(currentQ.getOPTB());
rdc.setText(currentQ.getOPTC());
qid++;
rda.setChecked(false);
rdb.setChecked(false);
rdc.setChecked(false);
//butNext.setEnabled(false);
}

最佳答案

if(rda.isChecked()||rdb.isChecked()||rdc.isChecked()){

RadioGroup grp=(RadioGroup)findViewById(R.id.radioGroup1);
RadioButton answer=(RadioButton)findViewById(grp.getCheckedRadioButtonId());
Log.d("yourans", currentQ.getANSWER()+" "+answer.getText());



if(currentQ.getANSWER().equals(answer.getText()))
{
score++;
Log.d("score", "Your score"+score);
}
if(qid<10)
{
currentQ=quesList.get(qid);
setQuestionView();

}
else
{
Intent intent = new Intent(MainAct.this, activity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}

inOnCheckChanged:

    radioGroup1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
if(rda.isChecked()||rdb.isChecked()||rdc.isChecked()){
butNext.setEnabled(true);
}else{
butNext.setEnabled(false);
}
}
});

关于java - 不知道将该代码放在我的 java 文件中的哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21431309/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com