How Can I Perform Input Validation In Android Using Toast

Ответить
harish
Сообщения: 2
Зарегистрирован: 12 ноя 2021, 13:16

How Can I Perform Input Validation In Android Using Toast

Сообщение harish » 12 ноя 2021, 13:27

Hello,

My simple requirement is that I want user validation when they enter data. For example, if a user enters a number, then my code should check whether the data entered by the user in the EditText is a number or not. And In case if the data entered fails it should display an error message telling the user about the problem. I have only a minor idea about this requirement. I think using Toast I can perform this validation. So please suggest to me how can code for this requirement. Omegle ome tv

I have also searched code for this requirement. But in this code, I am getting errors so please help me to solve this.

if (inputtext.getText().toString()==null || inputtext.getText().toString().trim().equals("")){
Toast.makeText(getContext(),"Input Field is Empty", Toast.LENGTH_LONG).show();
}
else{
//do what you want with the entered text
}

Ответить