mercredi 1 mai 2019

How do I prevent users from entering null texts?

I am setting up a database and I want to prevent users from putting null texts. How can I go about it?

public void AddData () {
        addbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                    if (name != null && surname != null && marks != null) {

                    String name1 = name.getText().toString();
                    String surname1 = surname.getText().toString();
                    String marks1 = marks.getText().toString();

                    boolean isInserted = mydb.insertdata(name1, surname1, marks1);

                    if (isInserted) {
                        Toast.makeText(MainActivity.this, "Data entered successfully", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(MainActivity.this, "Failed to enter Data", Toast.LENGTH_LONG).show();
                    }

                    }else if (name == null && surname == null && marks == null)  {
                        Toast.makeText(MainActivity.this, "Please enter Data", Toast.LENGTH_LONG).show();
                    }
            }
        });

}

Aucun commentaire:

Enregistrer un commentaire