I have a very basic question. I am trying to read values of three EditText fields and save them as one item in an arraylist using an arraya开发者_StackOverflow社区dapter. My question is how can I group the three variables I read from the EditTexts and add them as a single item in the arraylist?
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;
}
}
now add this class to ArrayList..
just like below,
ArrayList<editTextString> list = new ArrayList<editTextString>();
editTextString data = new editTextString("edit1","edit2","edit3")
list.add(data)
You can create a custom object that holds the strings from 3 edittexts
And the array list can be
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>();
adapter.add(edtxt1.getText()+edtxt2.getText()+edtxt3.getText())
this will stored in the adapter
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];
精彩评论