The Condor
The Condor

Reputation: 1054

Android - How to access an element data of a list that's inside another list?

Hy guys, I have encountered an issue with the lists.

What I want to do is to have a list of BasicNameValuePair elements, with this parameters:

I retrieve these informations from a JSON file.

I have to store this list INSIDE another list, which stores 10 elements of this kind.

I declared this two lists:

  1. public static List<NameValuePair> songsInfo = new ArrayList<NameValuePair>(5);
  2. static List dieciCanzoni = new ArrayList(10);

So the #2 must contain 10 elements of the #1.

How can I access data contained in the list inside the other list?

Please give me some advices, thank you all!

EDIT: Maybe I've found the solution!

Like suggested above, I've created generic String Lists and the code to control the data inside is this:

dieciCanzoni.get(i).get(5).compareTo("previewUrl")==0

I can use get(5) because I know that it will be the last value in the list, right?

Upvotes: 1

Views: 1047

Answers (1)

wtsang02
wtsang02

Reputation: 18873

List.get(ELEMENT_AT);

This retrives a list(in this case) of what ever kind of element of this list. Once you get a list, retrive what its in the list by doing it again.

List.get(ELEMENT_AT).get(ELEMENT_AT);

This will retrive an element(LIst) of the first list, and get an element in side.

But to make a List within a List, you need to do this:

List<CLASS> listParent=new ArrayList<CLASS>();
List<CLASS_IN> listChild=new ArrayList<CLASS_IN>();
addStuff();
for(...){
listParent.add(listChild);
}

Upvotes: 1

Related Questions