[英]Get the value inside 2D ArrayList in android?
I have a 2D array like ... 我有一个2D数组像......
ArrayList<ArrayList<MParsingClass>> 2d_arraylist = new ArrayList<ArrayList<MParsingClass>>();
I want to get all the Value of the internal Object class like the value of position ... 我想得到内部Object类的所有Value,如position的值...
2d_arraylist [0][1] and gradually so on.....
Any Help Please ?? 任何帮助请??
That would work if you were dealing with nested arrays , but you are dealing with nested ArrayList
s you have to use ArrayList
class methods to access its data, namely the get()
method. 如果您正在处理嵌套数组 ,那将会有效,但是您要处理嵌套的
ArrayList
您必须使用ArrayList
类方法来访问其数据,即get()
方法。
You need to use: 你需要使用:
2d_arraylist.get(0).get(1);
get(0)
gets the first row from your array of arrays (an ArrayList) get(0)
从数组数组中获取第一行(ArrayList)
get(1)
gets the second column from the row you have selected (an MParsingClass) get(1)
从您选择的行中获取第二列(MParsingClass)
You Have to make a 2 for loop like this ... 你必须像这样制作2 for循环......
for(int i=o ; i< size of 2d array ;i++)
// here you have to make another ArrayList which will get the positon of the "i th" //array of your 2D array.. //这里你必须创建另一个ArrayList,它将获得你的2D数组的“i th”//数组的位置。
ArrayList<MParsingClass> new_array_list = 2d_arraylist .get(position);
for(int j=o ; i<size of new_array_list ;i++)
new_array_list.get(your get value)
{
}
This should work: 这应该工作:
for(i=0; i<2d_arraylist.size(); i++) {
ArrayList<MParsingClass> temp = 2d_arraylist.get(i);
for(j=0; j<temp.size(); j++) {
MParsingClass obj = temp.get(j);
//To-Do .....
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.