In my app, I have around 5 editText boxes in every screen.I want to check if they are empty or not and if all the text boxes are not empty, then there is an intent which takes you to the next screen. I want to know what code to write.
Asked
Active
Viewed 447 times
3
-
1Can you post what you have until now? and what you have been trying to do? – Ami Hollander Jul 16 '16 at 07:59
-
Basically I am developing an app for people to create Portfolios. It has a few editText boxes so I wanna check if they are empty or not. I am only a beginner in Android App development. So I would be needing some help....... – Prateek Mahesh Jul 16 '16 at 13:44
1 Answers
0
Just add this code in your java file when you want to call the intent.
EditText editTextBox1 = (EditText) findViewById(R.id.your_editTextBox1_id);
EditText editTextBox2 = (EditText) findViewById(R.id.your_editTextBox2_id);
EditText editTextBox3 = (EditText) findViewById(R.id.your_editTextBox3_id);
EditText editTextBox4 = (EditText) findViewById(R.id.your_editTextBox4_id);
EditText editTextBox5 = (EditText) findViewById(R.id.your_editTextBox5_id);
if((editTextBox1.getText().length() != 0) && (editTextBox2.getText().length() != 0) && (editTextBox3.getText().length() != 0) && (editTextBox4.getText().length() != 0) && (editTextBox5.getText().length() != 0)){
//Start Activity
}
else{
//else show an error or anything you want
}
Here, just replace the your_editTextBox1_id
with the ID
you set in your xml
file.
If you want to check it when a Button
is clicked, just add this code in the OnClick
method of the button.

VatsalSura
- 926
- 1
- 11
- 27