带有自定义对象的数组列表

发布于 2024-12-07 05:50:22 字数 114 浏览 0 评论 0原文

我有一个非常基本的问题。我正在尝试读取三个 EditText 字段的值,并使用数组适配器将它们保存为数组列表中的一项。我的问题是如何将从 EditTexts 中读取的三个变量分组并将它们添加为数组列表中的单个项目?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云朵有点甜 2024-12-14 05:50:22
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)
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)
未央 2024-12-14 05:50:22

您可以创建一个自定义对象来保存 3 个编辑文本中的字符串

并且数组列表可以是

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

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>();
真心难拥有 2024-12-14 05:50:22
adapter.add(edtxt1.getText()+edtxt2.getText()+edtxt3.getText())

这将存储在适配器中

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

this will stored in the adapter

(り薆情海 2024-12-14 05:50:22
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];
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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文