1

我正在开发一个需要生成动态EditField. 我能够生成这个,但是当我尝试从这些字段中获取一个值时,我得到了EditField屏幕中所有字段最后生成的值。

我在下面粘贴了一些 J2ME 代码,但我不知道如何通过 BlackBerry API 调用获得相同的效果。

EditField ef;

for(int i = 0; i < 10; i++){
  EditField ef = new EditField("Name : "+i, "");
  add(ef);
  add(new SeparatorField());
} 


for(int i = 0; i < 10 ; i++){
  System.out.println(""+ef.getText());
}                                

private TextField fld, fld1;

for (int i = 0; i < 5; i++) {
  fld = new TextField("Name :", null, 30, TextField.ANY);
  append(fld);
}


for (int i = 0; i < 5; i++) {
  fld1 = (TextField) this.get(i);
  System.out.println(""+fld1.getString());
}
4

1 回答 1

0
I got my problem Solved. This answer is for those who are interested in it.

EditField ef;
Hashtable allEds = new Hashtable();

            for(int i = 0; i < 10; i++){
             EditField ef = new EditField("Name : "+i, "");
             add(ef);
             add(new SeparatorField());
             allEds.put(""+i, ef);
            } 


Enumeration e = allEds.elements();

while(e.hasMoreElements()){
                System.out.println(""+e.nextElement().toString());

            }
于 2012-11-16T06:03:39.700 回答