Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Android 如何用RadioButton返回分数?(做测试)_Android_Oop_Radio Button - Fatal编程技术网

Android 如何用RadioButton返回分数?(做测试)

Android 如何用RadioButton返回分数?(做测试),android,oop,radio-button,Android,Oop,Radio Button,我正在做MC测试。我想计算正确答案的分数。 这是我的密码。我想返回onRadioButtonClicked中的分数我该怎么做 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_general_test,

我正在做MC测试。我想计算正确答案的分数。 这是我的密码。我想返回onRadioButtonClicked中的分数我该怎么做

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_general_test, container, false);

    handInBtn=(Button) rootView.findViewById(R.id.handInBtn);       
    handInBtn.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            Toast toast = Toast.makeText(getActivity(), scores+"", Toast.LENGTH_LONG);
            toast.show();
        }});

    return rootView;
}

public void onRadioButtonClicked(View view) {
    // Is the button now checked?
    boolean checked = ((RadioButton) view).isChecked();

    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.Radio1a:
            if (checked)
                scores++;
        case R.id.Radio2a:
            if (checked)
                scores++;
    }
}

在安卓系统中,你们可以创建一个单选组,并且有一个redio group listener,所以你们可以选择单选按钮,并获取该按钮的值,若正确,和正确的答案进行比较,若正确,则递增,否则离开

for Example.
RadioGroup
    .setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
       Log.d("chk", "id" + checkedId);

            if (checkedId.gettext() == "Correct answer") {
                //some code
   correct++

            } else  {
                //some code
            }

        }

    });

在android中,您可以创建一个单选组,并且有一个重拨组侦听器,这样您就可以选择单选按钮并获取该按钮的值,然后与正确的答案进行比较,如果正确,则增加其他值,然后离开。您想在每次选中/取消选中后对分数值进行调整吗?!