6

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 arrayadapter. 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?

4 Answers 4

13
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)
Sign up to request clarification or add additional context in comments.

Comments

2

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>();

Comments

0
adapter.add(edtxt1.getText()+edtxt2.getText()+edtxt3.getText())

this will stored in the adapter

Comments

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];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.