Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.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 我的编辑文本赢了';不要在我的分数上加一分。android问答应用程序_Java_Android_Android Edittext_Radio Group - Fatal编程技术网

Java 我的编辑文本赢了';不要在我的分数上加一分。android问答应用程序

Java 我的编辑文本赢了';不要在我的分数上加一分。android问答应用程序,java,android,android-edittext,radio-group,Java,Android,Android Edittext,Radio Group,为什么我的程序在我提交正确答案时没有给我的分数加一分。 请帮忙。 以下是我的变量: public class MainActivity extends AppCompatActivity { int mscore =0 ; String q5R = "ripken"; String q5CR = "cal ripken"; String q5Cal = "cal"; @Override protected void onCreate(Bundle

为什么我的程序在我提交正确答案时没有给我的分数加一分。 请帮忙。 以下是我的变量:

public class MainActivity extends AppCompatActivity {
    int mscore =0 ;
    String q5R = "ripken";
    String q5CR = "cal ripken";
    String q5Cal = "cal";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void checkResult(View v) {
        //Access the RadioGroup view and save it to a variable.
        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.q1RadioBox);

        //Get the id of the RadioButton that is checked and save it
        //as an integer variable.
        int solutionId = radioGroup.getCheckedRadioButtonId();

        //Use if statements to respond based on whether
        //it is the id of the correct answer.
        if (solutionId == R.id.answer1) {
            mscore = mscore +1;
        } else {
                   mscore = mscore + 0;
               }

        //Access the RadioGroup2 view and save it to a variable.
        RadioGroup radioGroup2 = (RadioGroup) findViewById(R.id.q2RadioBox);

        //Get the id of the RadioButton that is checked and save it
        //as an integer variable.
        int solutionId2 = radioGroup2.getCheckedRadioButtonId();

        //Use if statements to respond based on whether
        //it is the id of the correct answer.
        if (solutionId2 == R.id.answer2) {
            mscore = mscore +1;
        } else {
                   mscore = mscore + 0;
               }

        CheckBox ws1966 = (CheckBox) findViewById(R.id.checkbox_1966);
        CheckBox ws1983 = (CheckBox) findViewById(R.id.checkbox_1983);
        CheckBox ws1970 = (CheckBox) findViewById(R.id.checkbox_1970);
        CheckBox ws1984 = (CheckBox) findViewById(R.id.checkbox_1984);
        CheckBox ws1961 = (CheckBox) findViewById(R.id.checkbox_1961);

        // Check for Required Answers
        if (ws1966.isChecked() && ws1983.isChecked() && ws1970.isChecked() && !ws1984.isChecked() && !ws1961.isChecked()) {
            mscore = mscore + 3;
        }

        EditText questionFive = (EditText) findViewById(R.id.question_5);
        String questionFiveAnswer = questionFive.getText().toString();
        if (questionFiveAnswer.equalsIgnoreCase(q5R) || questionFiveAnswer.equalsIgnoreCase(q5CR) || questionFiveAnswer.equalsIgnoreCase(q5Cal) ){
            mscore = mscore + 1;
        }

        EditText enterName = (EditText) findViewById(R.id.name_entry);
        String name = enterName.getText().toString();

        Context context = getApplicationContext();
        CharSequence text = name + " your score is: " + mscore + " points out of a possible 6 points";
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }


}

在布局文件中创建一个按钮,如下所示:

<Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Submit"
  android:onClick="calcScore"
  android:id="@+id/button"/>

在布局文件中创建一个按钮,如下所示:

<Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Submit"
  android:onClick="calcScore"
  android:id="@+id/button"/>

您需要先初始化int mscore

// initialize
int mscore = 0; 

// than add it
mscore += 1;

您需要先初始化int mscore

// initialize
int mscore = 0; 

// than add it
mscore += 1;

我不确定出了什么问题。但它现在似乎工作得很好。我感谢大家抽出时间来帮助我。

我不知道出了什么问题。但它现在似乎工作得很好。感谢大家花时间来帮助我。

这段代码是在您的activity onCreate()下还是在onClick()公共类MainActivity Extended AppCompatActivity{int mscore;String q5R=“ripken”String q5CR=“cal ripken”String q5Cal=“cal”;我对其进行了编辑,因此我的整个代码都在问题的上方。似乎if语句出于某种原因没有执行。我的单选按钮和复选框正在向分数添加分数,而不是我的edittext问题。这段代码是在activity onCreate()下还是在onClick()下公共类MainActivity扩展了AppCompatActivity{int mscore;String q5R=“ripken”String q5CR=“cal ripken”String q5Cal=“cal”;我已对其进行了编辑,因此我的整个代码都在问题上方。似乎if语句出于某种原因未执行。我的单选按钮和复选框正在向分数添加分数,而不是我的edittext问题。404未找到页面:(查看时,我没有看到任何xml布局文件。哪里是
R.layout.activity\u main
?我没有发现这段代码有任何错误。因此,只需复制到android studio并运行即可。它运行得非常好。这段代码没有任何问题。请确保您使用按钮的onClick属性调用checkResult。我没有发现任何其他错误。404页面没有错误und:(查看时,我没有看到任何xml布局文件。哪里是
R.layout.activity\u main
?我没有发现这段代码有任何错误。因此,只需复制到android studio并运行即可。它运行得非常好。这段代码没有任何错误。只要确保您使用按钮的onClick属性调用checkResult。我看不出任何其他错误。