no validation takes place and also no error occurs

62 views Asked by At

savebutton.setonclicklistenser:

if(edittext.getText().equals(""))

    {

    Toast.makeText(getBaseContext(),"enter data first",Toast.LENGTH_LONG);

    }
else

{

//all the view insert data query stuff

//toast.maketext("data inserted");

}

but It shows result: "data inserted"

on click view button it shows all the empty slots which i added as string on tv.append("slot 1 "+slot1+""); veiws all the slots like "slot1" string i passed in append method.

3

There are 3 answers

4
A.S On BEST ANSWER

change if(edittext.gettext().equals("")) condition to if(edittext.getText().toString().trim().equals("")) add toString().

0
Rishi Paul On

Use Like This

if(edittext.getText().toString().equals(""))
    {

       Toast.makeText(getApplicationContext(),"enter data first",Toast.LENGTH_LONG).show();
    }
else
{
 //all the view insert data query stuff

//toast.maketext("data inserted");
}
5
Kinjal On

You can write this

if(edittext.getText().toString().equals("")){
          Toast.maketext(getApplicationcontext(),"enter data first",toast.length_long);
}

Instead of this

if(edittext.gettext().equals("")){
               Toast.maketext(getbasecontext(),"enter data first",toast.length_long); 
}