Arraylist with custom objects

I have a very simple question. I am trying to read the values โ€‹โ€‹of three EditText fields and save them as a single element in an arraylist using the arrayadapter. My question is, how can I group the three variables that I read from EditTexts and add them as one element in an arraylist?

+4
source share
4 answers
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 ..

as shown below

 ArrayList<editTextString> list = new ArrayList<editTextString>(); editTextString data = new editTextString("edit1","edit2","edit3") list.add(data) 
+11
source

You can create a custom object that contains lines of 3 editors

And the list of arrays could 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>(); 
+1
source
 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]; 
0
source
 adapter.add(edtxt1.getText()+edtxt2.getText()+edtxt3.getText()) 

it will be saved in the adapter

0
source

All Articles