我有这段代码:
List<EditText> someList = new ArrayList<EditText>();
//Let's say we'd like to add 10 EditTexts
for(int i = 0; i < 10; i++){
EditText t1 = new EditText(); //The EditText you'd like to add to the list
t1.setText("lol"); //Give the EditText the value 'lol'
someList.add(t1); //Add the EditText to the list
}
//Go over the list and get the values
for(EditText t : someList){
String val = t.getText(); //Get the value for the temp EditText variable t
}
我想知道如何获得带有索引号的arraylist文本?喜欢:somelist[2]
答案 0 :(得分:3)
这样的事情可以解决问题:
int index = 2;
EditText et = someList.get(index);
Log.d(TAG, et.getText());
答案 1 :(得分:2)
试试这个:
EditText t = someList.get(2);
String text=t.getText().toString();
答案 2 :(得分:0)
试试这个
EditText text2=someList.get(2);
答案 3 :(得分:0)
使用它:
somelist.get(2);
这将返回位置2的edittext。