Еще один вопрос от новичка-любителя, но у меня есть проблема, с которой я не могу разобраться.
Я создал макет с 10 вопросами, ответ на который "ДА", "НЕТ "или" СОМНЕНИЕ ".Это я создал в 10 радиогруппах с 3 вышеуказанными вариантами в радиопереключателях.Теперь я могу найти много вопросов о выборе в одной радиогруппе, но что, если я хочу сравнить варианты в 10 радиогруппах.
В основном мне нужно показать одно изображение зеленого цвета, если выборво всех радиогруппах это «ДА».Если только один вопрос «Сомнительный», он нужен, чтобы заменить все и отобразить «ЖЕЛТЫЙ» образ.Наконец, если только один ответ «НЕТ», мне нужно отобразить красное изображение.
Как мне это сделать, и, поскольку я новичок в этом, пожалуйста, ответьте примерами кода.
Покамой код выглядит следующим образом: (не обращайте внимания на тост, поскольку это просто для проверки того, что радиокнопки работают как задумано)
package com.example.captainlarsen.crewassistant;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class TaskSafetyActivity extends AppCompatActivity{
RadioGroup choice1;
RadioButton button1;
RadioGroup choice2;
RadioButton button2;
RadioGroup choice3;
RadioButton button3;
RadioGroup choice4;
RadioButton button4;
RadioGroup choice5;
RadioButton button5;
RadioGroup choice6;
RadioButton button6;
RadioGroup choice7;
RadioButton button7;
RadioGroup choice8;
RadioButton button8;
RadioGroup choice9;
RadioButton button9;
RadioGroup choice10;
RadioButton button10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task_safety);
choice1 = (RadioGroup) findViewById(R.id.radiogroup1);
choice2 = (RadioGroup) findViewById(R.id.radiogroup2);
choice3 = (RadioGroup) findViewById(R.id.radiogroup3);
choice4 = (RadioGroup) findViewById(R.id.radiogroup4);
choice5 = (RadioGroup) findViewById(R.id.radiogroup5);
choice6 = (RadioGroup) findViewById(R.id.radiogroup6);
choice7 = (RadioGroup) findViewById(R.id.radiogroup7);
choice8 = (RadioGroup) findViewById(R.id.radiogroup8);
choice9 = (RadioGroup) findViewById(R.id.radiogroup9);
choice10 = (RadioGroup) findViewById(R.id.radiogroup10);
}
public void choice1(View v) {
int RadioButtonID1 = choice1.getCheckedRadioButtonId();
button1 = findViewById(RadioButtonID1);
switch (v.getId()) {
case R.id.radioButtonYes1:
Toast.makeText(this,"Choice1 is YES", Toast.LENGTH_LONG).show();
break;
case R.id.radioButtonDoubt1:
Toast.makeText(this,"Choice1 is DOUBT", Toast.LENGTH_LONG).show();
break;
case R.id.radioButtonNo1:
Toast.makeText(this,"Choice1 is NO", Toast.LENGTH_LONG).show();
break;
}
}
public void choice2(View v) {
int RadioButtonID2 = choice2.getCheckedRadioButtonId();
button2 = (RadioButton) findViewById(RadioButtonID2);
switch (v.getId()) {
case R.id.radioButtonYes2:
Toast.makeText(this,"Choice2 is YES", Toast.LENGTH_LONG).show();
break;
case R.id.radioButtonDoubt2:
Toast.makeText(this,"Choice2 is DOUBT", Toast.LENGTH_LONG).show();
break;
case R.id.radioButtonNo2:
Toast.makeText(this,"Choice2 is NO", Toast.LENGTH_LONG).show();
break;
}
}
public void choice3(View v) {
int RadioButtonID3 = choice3.getCheckedRadioButtonId();
button3 = findViewById(RadioButtonID3);
}
public void choice4(View v) {
int RadioButtonID4 = choice4.getCheckedRadioButtonId();
button4 = findViewById(RadioButtonID4);
}
public void choice5(View v) {
int RadioButtonID5 = choice5.getCheckedRadioButtonId();
button5 = findViewById(RadioButtonID5);
}
public void choice6(View v) {
int RadioButtonID6 = choice6.getCheckedRadioButtonId();
button6 = findViewById(RadioButtonID6);
}
public void choice7(View v) {
int RadioButtonID7 = choice7.getCheckedRadioButtonId();
button7 = findViewById(RadioButtonID7);
}
public void choice8(View v) {
int RadioButtonID8 = choice8.getCheckedRadioButtonId();
button8 = findViewById(RadioButtonID8);
}
public void choice9(View v) {
int RadioButtonID9 = choice9.getCheckedRadioButtonId();
button9 = findViewById(RadioButtonID9);
}
public void choice10(View v) {
int RadioButtonID10 = choice10.getCheckedRadioButtonId();
button10 = findViewById(RadioButtonID10);
Я действительно надеюсь, что один из вас может помочь мне, когда я застрял; o)
Спасибо.