I have three textboxes ct1,ct2,ct3. I have to use a for loop 1 to 3 and check whether the textboxes are empty. So, inside the for loop, how do I represent it? For example,
for(i=0;i<=3;i++)
{
if(ct+i.getText()) // I know I'm wrong
{
}
}
I have three textboxes ct1,ct2,ct3.
There's your problem to start with. Instead of using three separate variables, create an array or collection:
TextBox[] textBoxes = new TextBox[3];
// Populate the array...
Or:
List<TextBox> textBoxes = new ArrayList<TextBox>();
// Populate the list...
Then in your loop:
// Note the < here - not <=
for (int i = 0; i < 3; i++) {
// If you're using the array
String text = textBoxes[i].getText();
// or for the list...
String text = textBoxes.get(i).getText();
}
Or if you don't need the index:
for (TextBox textBox : textBoxes) {
String text = textBox.getText();
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With