Form a script correctly in Android Studio

0

I need to validate the entries in the registers of my application and everything runs fine, only if a user is placed with a key Empty accepts it, I need to accommodate this ... then proceed to implement the code where valid

public void onClickAceptar (View view) {
    //metodo utilizado para guardar en la BD
    //1)las variables usadas para llenar la tabla usuario

    String auxn = aetidr.getText().toString();  //tomamos el nombre
    String auxp = aetpassr.getText().toString();//tomamos la clave
    String auxc = aetpasscr.getText().toString();//con este validamos la clave

    //verificamos QUE NADA QUEDE SIN LLENAR!!!

    //si la variable que acepta el nombre esta vacia nos pedira ingresar usuario
    if (auxn.isEmpty()){

        Toast.makeText(getApplicationContext(),"Ingrese un Usuario",Toast.LENGTH_LONG).show();

     //sino... si la clave es vacia entonces te pide que coloques una clave
    }else if (auxp == null){

        Toast.makeText(getApplicationContext(),"Ingrese una contraseña",Toast.LENGTH_LONG).show();


        //si la clave de confirmacion es igual a la clave entonces guardalo en el sistema

   //-----AQUI ES EL PROBLEMA!! NO ESTOY SEGURO PERO NO DOY CON EL ------
     }else if (auxp.equals(auxc)){

        //abrimos la base de datos
        SQLite admin = new SQLite(this,"administracion", null, 1);

        //creamos variable re-escribible
        SQLiteDatabase bd = admin.getWritableDatabase();

        //creamos un contenedor llamado registro
        ContentValues registro = new ContentValues();

        //cargamos los datos en el contenedor..
        //diciendo... "registro se cargue con variable "usuario" y el valor de auxn
        registro.put("usuario", auxn);
        //diciendo... "registro se cargue con variable "clave" y el valor de auxn
        registro.put("clave", auxp);
        //estas variables deben ser EXACTAS a la de la tabla!


        // los inserto en la base de datos diciendo:
        //variable db (creada arriba) insertara los valores EN la tabla "usuarios", null, con el contenido de "registro"

        bd.insert("usuarios", null, registro);

        //cerramos bd
        bd.close();

        // ponemos los campos a vacío para insertar el siguiente usuario
        aetidr.setText("");
        aetpasscr.setText("");
        aetpassr.setText("");

        Toast.makeText(this, "Datos del usuario cargados", Toast.LENGTH_SHORT).show();
    }
    
asked by ERny JOsé HIdalgo COrrea 29.11.2016 в 19:16
source

2 answers

0

use the equals option in this way

if (auxn.equals("")){//tu mensaje de error}

Equal to not use Toast you can use properties of EditText

aetidr.setError("Usuario Requerido");

It would stay like this

if (auxn.equals("")){
     aetidr.setError("Usuario Requerido");
}
    
answered by 29.11.2016 / 19:48
source
0

have proof this

else if (auxp.equals("")){

    Toast.makeText(getApplicationContext(),"Ingrese una contraseña",Toast.LENGTH_LONG).show();

 }
    
answered by 29.11.2016 в 19:24