我有一个非常基本的问题。我试图读取三个EditText字段的值,并使用arrayadapter将它们保存为arraylist中的一个项目。我的问题是如何将我从EditTexts中读取的三个变量分组并将它们作为单个项添加到arraylist中?
答案 0 :(得分:12)
class editTextString{
private String str1
private String str2
private String str3
public editTextString(String data1,String data2,String data3){
str1 = data1;
str2 = data2;
str3 = data3;
}
}
现在将此类添加到ArrayList ..
就像下面一样,
ArrayList<editTextString> list = new ArrayList<editTextString>();
editTextString data = new editTextString("edit1","edit2","edit3")
list.add(data)
答案 1 :(得分:2)
您可以创建一个自定义对象来保存3个edittexts中的字符串
数组列表可以是
public class CustomObj{
String str1;
String str2;
String str3;
public CustomObj(String s1,String s2,String s3){
this.str1 = s1;
this.str2 = s2;
this.str3 = s3;
}
}
ArrayList<CustomObj> customObjList = new ArrayList<CustomObj>();
答案 2 :(得分:0)
public class MyObject {
private String string1;
private String string2;
private String string3;
public MyObject(String s1,String s2,String s3) {
string1 = s1;
string2 = s2;
string3 = s3;
}
public toString() {
return string1 + " " + string 2 + " " +string3;// your string representation
}
}
MyObject[] adapterList = new MyObect[1];
答案 3 :(得分:0)
adapter.add(edtxt1.getText()+edtxt2.getText()+edtxt3.getText())
这将存储在适配器
中