Android - (Validar)comprobar si alguno de los RadioButton de un RadioGroup ha sido seleccionado

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 118 puestos en Android (en relación al último mes)
Gráfica de Android

(Validar)comprobar si alguno de los RadioButton de un RadioGroup ha sido seleccionado

Publicado por Luis Alberto (1 intervención) el 05/01/2020 16:23:31
Buenas buenas.

Programa

En la imagen que les envio, tengo un Radio Group y quisiera que me ayuden para agregarle validacion, que al momento de no seleccionar nada, me salgo un mensaje "Seleccione un Item"

INTENTE HACERLO DE ESTA FORMA PERO NO FUNCIONA...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
public class MainActivity extends AppCompatActivity {
 
    RadioGroup rgNotas;
    EditText txtTP;
    EditText txtEP;
    EditText txtEF;
    Button btnMostrar;
    TextView lblResultado;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        rgNotas = findViewById(R.id.rgNotas);
        txtTP = findViewById(R.id.txtTP);
        txtEP = findViewById(R.id.txtEP);
        txtEF = findViewById(R.id.txtEF);
        btnMostrar = findViewById(R.id.btnMostrar);
        lblResultado = findViewById(R.id.lblResultado);
 
    }
 
    public void mostradatosseleccionados(View view){
 
        int rbSeleccionado= rgNotas.getCheckedRadioButtonId();
        RadioButton rb= findViewById(rbSeleccionado);
       // RadioGroup grupoun = (RadioGroup) findViewById(R.id.Grupo1);
        if (rgNotas.getCheckedRadioButtonId() == -1)
        {
            // No hay ningun radio seleccionado
            Toast.makeText(getApplicationContext(),
                    "Seleccione una materia",
                    Toast.LENGTH_LONG).show();
        }
 
 
 
        int nota1 = Integer.valueOf(txtTP.getText().toString());
 
 
 
        if (nota1 <=20){
           // txtTP.setText(nota1+" ");
 
        }
 
        if (txtTP.getText().equals("")){
 
            txtTP.setError("Agregar el Puntaje del Trabajo Practico");
 
        }
        int nota2 = Integer.valueOf(txtEP.getText().toString());
 
        if (nota2 <=30){
           // txtEP.setText(nota2+" ");
        }
        if (txtEP.getText().equals("")){
 
           txtEP.setError("Agregar el Puntaje del Examen parcial");
 
        }
        int nota3 = Integer.valueOf(txtEF.getText().toString());
 
        if (nota3 <= 60){
          // txtEF.setText(nota3+" ");
        }
        if (txtEF.getText().equals("")){
 
            txtEF.setError("Agregar el Puntaje del Examen final");
 
        }
        int notatotal = nota1 + nota2 + nota3;
        //lblResultado.setText("Calificacion Total"+rb.getText().toString()+notatotal);
 
        int Notafinal = notatotal;
     //   lblResultado.setText("Notafinal es :"+rb.getText().toString()+Notafinal);
 
 
 
        if (Notafinal >= 91 && Notafinal <=100){
            lblResultado.setText("La Calificacion del Modulo : " + rb.getText().toString()+" Es :" + Notafinal+ " "+"Cinco");
        }
        if (Notafinal >= 81 && Notafinal <=90){
            lblResultado.setText("La Calificacion del Modulo : " + rb.getText().toString()+" Es :" + Notafinal+ " "+"Cuatro ");
        }
        if (Notafinal >= 71 && Notafinal <=80){
            lblResultado.setText("La Calificacion del Modulo : " + rb.getText().toString()+" Es :" + Notafinal+" "+ "Tres");
        }
        if (Notafinal >= 60 && Notafinal <=70){
            lblResultado.setText("La Calificacion del Modulo : " + rb.getText().toString()+" Es :" + Notafinal+" "+ "Dos");
        }
        if (Notafinal>= 1 && Notafinal<= 59){
            lblResultado.setText("La Calificacion del Modulo : " + rb.getText().toString()+" Es :" + Notafinal+" "+ "Uno");
        }
 
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Cubel
Val: 8
Ha aumentado su posición en 7 puestos en Android (en relación al último mes)
Gráfica de Android

(Validar)comprobar si alguno de los RadioButton de un RadioGroup ha sido seleccionado

Publicado por Cubel (3 intervenciones) el 24/01/2020 16:21:28
Con esto debería ser suficiente mientras cada item del RadioGroup tenga un id.

1
int selectedId = rgNotas.getCheckedRadioButtonId();
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar