How can I compare a String-array

-1
else if (pregunta1.getItemAtPosition(position).equals("2.-Coloque la el comando para entrar a la terminal de PowerShell")){
            AlertDialog.Builder ad=new AlertDialog.Builder(Matematicas.this);
            ad.setTitle("Indique la respuesta correcta");
            ad.setSingleChoiceItems(R.array.Pregunta2, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(Matematicas.this, "" + which, Toast.LENGTH_LONG);
                }
            });
            ad.setPositiveButton("confirmar", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {


                    String[] esto=getResources().getStringArray(R.array.Pregunta2);


                    if (esto.toString().equals("A)PowerShell"))
                        Toast.makeText(getApplicationContext(), "si", Toast.LENGTH_SHORT).show();
                    else
                        Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_SHORT).show();
                }
            });
            ad.show();
    
asked by AlejandRo Morales Gomez 19.11.2018 в 00:00
source

1 answer

-1

To compare the text of a radio button, with a string, getText is used:

 if(radiobutton.getText().equals("texto"))

To compare it with a String array, use a for, in this case if some of the elements of the array (this) matches the text of the radio button:

 for(int i=0; i<esto.length ; i++) {
        if (esto[i].equals(tuRadioButton.getText()) ) {
            Toast.makeText(getApplicationContext(), "si", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_SHORT).show();
        }
    }
    
answered by 19.11.2018 в 03:08