Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不知道在我的java文件中放在哪里_Java_Android_Eclipse - Fatal编程技术网

不知道在我的java文件中放在哪里

不知道在我的java文件中放在哪里,java,android,eclipse,Java,Android,Eclipse,我不知道该将此代码放在何处,以便用户在选择单选按钮之前不会转到其他页面 这是我不知道该怎么写的代码: if(rda.isChecked() == true) { butNext.setEnabled(true); } if(rdb.isChecked() == true) { butNext.setEnabled(true); } if(rdc.isChecked() == true) { butNext.setEnabled(true); } else {

我不知道该将此代码放在何处,以便用户在选择
单选按钮之前不会转到其他页面

这是我不知道该怎么写的代码:

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);
}
列表查询列表;
智力得分=0;
int-qid=0;
问题Q;
文本视图TXT问题;
单选按钮rda、rdb、rdc;
按钮butNext;
放射组放射组1;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_页面);
DBase db=新的DBase(本);
quesList=db.getAllQuestions();
currentQ=quesList.get(qid);
txtQuestion=(TextView)findViewById(R.id.textView1);
rda=(单选按钮)findViewById(R.id.rda);
rdb=(单选按钮)findViewById(R.id.rdb);
rdc=(单选按钮)findViewById(R.id.rdc);
但是下一步=(按钮)findViewById(R.id.button1);
setQuestionView();
但是next.setOnClickListener(newview.OnClickListener(){
@凌驾
公共void onClick(视图v)
{
放射组grp=(放射组)findViewById(R.id.RadioGroup 1);
RadioButton answer=(RadioButton)findViewById(grp.getCheckedRadioButtonId());
Log.d(“yourans”,currentQ.getANSWER()+“”+answer.getText());
if(currentQ.getANSWER().equals(answer.getText()))
{
分数++;
Log.d(“分数”、“你的分数”+分数);
}

如果(qid对于您的查询,您只需要在单击此单选按钮时启动Intent

例如:使用条件检查,以确保您的收音机已被检查

i、 e

我希望这能消除你的疑虑

就放置代码而言,您可以仅在onCreate()方法中放置相同的代码。这实际上取决于您的需要


干杯!

您只需在您的团队的checkedChangeListener()方法上调用它即可

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);
        }
    }
});

把它放在一个方法中,并在onResume()和单选按钮的clicklistener中调用它。先生,我应该把这段代码放在哪里?对不起,在调用按钮的onClick事件之前,我是androidon oncrete()方法的新手。setOnCheckedChangeListener得到了一条下划线
    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);
            }
        }
    });
if( radio_b.ischecked()){
// start Intent over here 
}else{
// Toast a message to user to select same
}
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);
        }
    }
});