如何在Android中使用单选按钮计算分数?

huangapple go评论85阅读模式
英文:

How to calculate score using Radio buttons in Android?

问题

以下是你提供的代码的翻译部分:

这是 Activity 类:

public class CoughTest extends AppCompatActivity {

    int score = 0;
    RadioGroup rg1, rg2, rg3, rg4, rg5;
    RadioButton rb;

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

        rg1 = (RadioGroup) findViewById(R.id.rgroup1);
        rg2 = (RadioGroup) findViewById(R.id.rgroup2);
        rg3 = (RadioGroup) findViewById(R.id.rgroup3);
        rg4 = (RadioGroup) findViewById(R.id.rgroup4);
        rg5 = (RadioGroup) findViewById(R.id.rgroup5);
    }

    public void rbClicked(View view) {
        int radioButtonId = rg1.getCheckedRadioButtonId();
        rb = (RadioButton) findViewById(radioButtonId);

        boolean checked = ((RadioButton) view).isChecked();

        switch (view.getId()){
            case R.id.yes1:
                score = score + 20;
                break;
            case R.id.no1:
                score = 0;
                break;
            case R.id.yes2:
                score = score + 20;
                break;
            case R.id.no2:
                score = 0;
                break;
            case R.id.yes3:
                score = score + 20;
                break;
            case R.id.no3:
                score = 0;
                break;
            case R.id.yes4:
                score = score + 20;
                break;
            case R.id.no4:
                score = 0;
                break;
            case R.id.yes5:
                score = score + 20;
                break;
            case R.id.no5:
                score = 0;
                break;
        }
    }
}

这是 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CoughTest">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_marginLeft="10dp"
            android:fontFamily="@font/roboto_bold"
            android:text="Do you have a cough?"
            android:textColor="#100D40"
            android:textSize="20sp" />

        <!-- 其他部分省略 -->

    </LinearLayout>
</ScrollView>

请注意,我只翻译了你提供的代码部分,其余内容均被省略。

英文:

I have been developing a form which uses Radio buttons and has a list of questions.

When the user clicks on Yes radio button for every question, I want to increment the score by 20. If the user clicks the No radio button, the score should be 0.

Take a look at the code.

This is the Activity class

CoughTest.java

  public class CoughTest extends AppCompatActivity {
int score= 0;
RadioGroup rg1,rg2,rg3,rg4,rg5;
RadioButton rb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cough_test);
rg1 = (RadioGroup) findViewById(R.id.rgroup1);
rg2 = (RadioGroup) findViewById(R.id.rgroup2);
rg3 = (RadioGroup) findViewById(R.id.rgroup3);
rg4 = (RadioGroup) findViewById(R.id.rgroup4);
rg5 = (RadioGroup) findViewById(R.id.rgroup5);
}
public void rbClicked(View view) {
int radioButtonId = rg1.getCheckedRadioButtonId();
rb =(RadioButton) findViewById(radioButtonId);
boolean checked = ((RadioButton) view).isChecked();
switch (view.getId()){
case R.id.yes1:
score = score + 20;
break;
case R.id.no1:
score = 0;
break;
case R.id.yes2:
score = score + 20;
break;
case R.id.no2:
score = 0;
break;
case R.id.yes3:
score = score + 20;
break;
case R.id.no3:
score = 0;
break;
case R.id.yes4:
score = score + 20;
break;
case R.id.no4:
score = 0;
break;
case R.id.yes5:
score = score + 20;
break;
case R.id.no5:
score = 0;
break;
}
}
}

This is the XML file

activity_cough_test.xml

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
tools:context=&quot;.CoughTest&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textView11&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;16dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Do you have a cough?&quot;
android:textColor=&quot;#100D40&quot;
android:textSize=&quot;20sp&quot; /&gt;
&lt;RadioGroup
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/rgroup1&quot;&gt;
&lt;RadioButton
android:id=&quot;@+id/yes1&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;Yes&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/no1&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;No&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;/RadioGroup&gt;
&lt;TextView
android:id=&quot;@+id/soar_throat&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;20dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Do you have a soar throat?&quot;
android:textColor=&quot;#100D40&quot;
android:textSize=&quot;20sp&quot; /&gt;
&lt;RadioGroup
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/rgroup2&quot;&gt;
&lt;RadioButton
android:id=&quot;@+id/yes2&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;Yes&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/no2&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;No&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;/RadioGroup&gt;
&lt;TextView
android:id=&quot;@+id/fever&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;24dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Do you have fever?&quot;
android:textColor=&quot;#100D40&quot;
android:textSize=&quot;20sp&quot; /&gt;
&lt;RadioGroup
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/rgroup3&quot;&gt;
&lt;RadioButton
android:id=&quot;@+id/yes3&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;Yes&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/no3&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;No&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;/RadioGroup&gt;
&lt;TextView
android:id=&quot;@+id/tiredness&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;24dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Do you have tiredness?&quot;
android:textColor=&quot;#100D40&quot;
android:textSize=&quot;20sp&quot; /&gt;
&lt;RadioGroup
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/rgroup4&quot;&gt;
&lt;RadioButton
android:id=&quot;@+id/yes4&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;Yes&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/no4&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;No&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;/RadioGroup&gt;
&lt;TextView
android:id=&quot;@+id/breathing&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;20dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Do you have difficulty in breathing?&quot;
android:textColor=&quot;#100D40&quot;
android:textSize=&quot;20sp&quot; /&gt;
&lt;RadioGroup
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/rgroup5&quot;&gt;
&lt;RadioButton
android:id=&quot;@+id/yes5&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;Yes&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/no5&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:onClick=&quot;rbClicked&quot;
android:text=&quot;No&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;/RadioGroup&gt;
&lt;/LinearLayout&gt;
&lt;/ScrollView&gt;

答案1

得分: 1

我将建议这种方法:

CoughTest.java:

public class CoughTest extends AppCompatActivity {

    private Button btnSubmit, btnReset;
    private TextView finalScore;
    private RadioButton cough, sourThroat, fever, tiredness, breathing;

    private int score = 0;

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

        btnSubmit = (Button) findViewById(R.id.btnSubmit);
        btnReset = (Button) findViewById(R.id.btnReset);
        finalScore = (TextView) findViewById(R.id.textFinalScore);

        cough = (RadioButton) findViewById(R.id.cough);
        sourThroat = (RadioButton) findViewById(R.id.sour_throat);
        fever = (RadioButton) findViewById(R.id.fever);
        tiredness = (RadioButton) findViewById(R.id.tiredness);
        breathing = (RadioButton) findViewById(R.id.breathingDifficulty);

        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cough.isChecked()) {
                    score = score + 20;
                } else {
                    score = score + 0;
                }

                if (sourThroat.isChecked()) {
                    score = score + 20;
                } else {
                    score = score + 0;
                }

                if (fever.isChecked()) {
                    score = score + 20;
                } else {
                    score = score + 0;
                }

                if (tiredness.isChecked()) {
                    score = score + 20;
                } else {
                    score = score + 0;
                }

                if (breathing.isChecked()) {
                    score = score + 20;
                } else {
                    score = score + 0;
                }

                // 最后显示您的得分。
                Toast.makeText(getApplicationContext(), "得分是:" + score, Toast.LENGTH_SHORT).show();

            }
        });
        // 重置所有内容
        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                score = 0;
                cough.setChecked(false);
                fever.setChecked(false);
                breathing.setChecked(false);
                tiredness.setChecked(false);
                sourThroat.setChecked(false);
            }
        });
    }
}

回到你的XML:我进行了修改。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CoughTest">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".CoughTest">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/roboto_bold"
                android:text="请勾选(✓)如果您有这些症状。"
                android:textColor="#100D40"
                android:textSize="16sp" />

            <RadioButton
                android:id="@+id/cough"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/roboto_bold"
                android:text="咳嗽"
                android:textColor="#100D40" />


            <RadioButton
                android:id="@+id/sour_throat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/roboto_bold"
                android:text="喉咙痛"
                android:textColor="#100D40" />


            <RadioButton
                android:id="@+id/fever"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/roboto_bold"
                android:text="发热"
                android:textColor="#100D40" />


            <RadioButton
                android:id="@+id/tiredness"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/roboto_bold"
                android:text="疲劳"
                android:textColor="#100D40" />


            <RadioButton
                android:id="@+id/breathingDifficulty"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/roboto_bold"
                android:text="呼吸困难"
                android:textColor="#100D40" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="提交"
                android:id="@+id/btnSubmit"
                android:layout_marginStart="50sp"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="重置"
                android:layout_marginTop="5sp"
                android:id="@+id/btnReset"
                android:layout_marginStart="50sp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20sp"
                android:layout_marginStart="20sp"
                android:hint="您的分数在这里"
                android:textColor="#000000"
                android:id="@+id/textFinalScore"/>

        </LinearLayout>
    </ScrollView>

</RelativeLayout>

我已删除了单选按钮组。只需提示用户在同意时单击它。这意味着如果他们的答案是“是”,请勾选单选按钮,否则保持未选中。希望这有所帮助。

顺便说一下,它的工作原理如下:如何在Android中使用单选按钮计算分数?

英文:

I will suggest this method:

CoughTest.java:

public class CoughTest extends AppCompatActivity {
private Button btnSubmit, btnReset;
private TextView finalScore;
private RadioButton cough, sourThroat, fever, tiredness, breathing;
private  int score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cough_test);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
btnReset = (Button) findViewById(R.id.btnReset);
finalScore = (TextView) findViewById(R.id.textFinalScore);
cough = (RadioButton) findViewById(R.id.cough);
sourThroat = (RadioButton) findViewById(R.id.sour_throat);
fever = (RadioButton) findViewById(R.id.fever);
tiredness = (RadioButton) findViewById(R.id.tiredness);
breathing = (RadioButton) findViewById(R.id.breathingDifficulty);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cough.isChecked()) {
score = score + 20;
} else {
score = score + 0;
}
if (sourThroat.isChecked()) {
score = score + 20;
} else {
score = score + 0;
}
if (fever.isChecked()) {
score = score + 20;
} else {
score = score + 0;
}
if (tiredness.isChecked()) {
score = score + 20;
} else {
score = score + 0;
}
if (breathing.isChecked()) {
score = score + 20;
} else {
score = score + 0;
}
//Finally show your score.
Toast.makeText(getApplicationContext(), &quot;Score is: &quot; + score, Toast.LENGTH_SHORT).show();
}
});
//Resetting everything
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
score = 0;
cough.setChecked(false);
fever.setChecked(false);
breathing.setChecked(false);
tiredness.setChecked(false);
sourThroat.setChecked(false);
}
});
}

}

Coming back to your XML: I modified it.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;RelativeLayout
xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
tools:context=&quot;.CoughTest&quot;&gt;
&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
tools:context=&quot;.CoughTest&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;TextView
android:id=&quot;@+id/textView12&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;16dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Please check (✓) if you show the symptom.&quot;
android:textColor=&quot;#100D40&quot;
android:textSize=&quot;16sp&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/cough&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;cough&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/sour_throat&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Sour Throat&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/fever&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Fever&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/tiredness&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;tiredness&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/breathingDifficulty&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;12dp&quot;
android:layout_marginLeft=&quot;10dp&quot;
android:fontFamily=&quot;@font/roboto_bold&quot;
android:text=&quot;Breathing Difficulty&quot;
android:textColor=&quot;#100D40&quot; /&gt;
&lt;Button
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;submit&quot;
android:id=&quot;@+id/btnSubmit&quot;
android:layout_marginStart=&quot;50sp&quot;/&gt;
&lt;Button
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Reset&quot;
android:layout_marginTop=&quot;5sp&quot;
android:id=&quot;@+id/btnReset&quot;
android:layout_marginStart=&quot;50sp&quot;/&gt;
&lt;TextView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginTop=&quot;20sp&quot;
android:layout_marginStart=&quot;20sp&quot;
android:hint=&quot;Your Score Here&quot;
android:textColor=&quot;#000000&quot;
android:id=&quot;@+id/textFinalScore&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;/ScrollView&gt;
&lt;/RelativeLayout&gt;

I have removed the radio groups. Just prompt your user to click it when they agree.
Means if their answer is YES, then please check the radio button else leave it unchecked.
Hope that helps.

By the way this is how it works:
如何在Android中使用单选按钮计算分数?

答案2

得分: 0

只需在您的switch case之后将分数设置到您的textView中:

yourTextView.setText(String.valueOf(score));
英文:

just set score into your textView after your switch case :

yourTextView = String.ValueOf(score); 

huangapple
  • 本文由 发表于 2020年4月6日 12:08:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/61052823.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定