ArrayList的自定义对象 [英] arraylist with custom objects

查看:143
本文介绍了ArrayList的自定义对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题。我想看了三的EditText字段的值,并且使用arrayadapter它们保存为一个项目在一个ArrayList。我的问题是我怎么能集团的三个变量我从EditTexts阅读并ArrayList中添加为一个单一的项目?


解决方案

 类editTextString {
私人字符串STR1
私人字符串STR2
私人字符串STR3公共editTextString(字符串数据1,字符串数据2,字符串数据3){STR1 = DATA1;
STR2 = DATA2;
STR3 =数据3;
}}

现在添加这个类ArrayList的..

就像下面,

 的ArrayList< editTextString>名单=新的ArrayList< editTextString>();editTextString数据=新editTextString(EDIT1,EDIT2,EDIT3)list.add(数据)

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?

解决方案

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)

这篇关于ArrayList的自定义对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆