在另一个变量中插入一个变量 [英] Inserting a variable amidst another variable

查看:41
本文介绍了在另一个变量中插入一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个文本框ct1、ct2、ct3.我必须使用 for 循环 1 到 3 并检查文本框是否为空.那么,在 for 循环中,我如何表示它?例如,

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
     {
     }

}

推荐答案

我有三个文本框ct1、ct2、ct3.

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...

或者:

List<TextBox> textBoxes = new ArrayList<TextBox>();
// Populate the list...

然后在你的循环中:

// 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();
    ...
}

这篇关于在另一个变量中插入一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆