up vote 0 down vote favorite
share [g+] share [fb]

I have an arraylist for some kind of objects. These objects, have some attributes like strings and some integers. But also, an arraylist of another kind of objects.

I create the 2nd object first. And group them into an arraylist of this kind of objects. Then i check if this arraylist is empty. If its not, then i create the other object, and pass it the first arrayList. And put it inside another arraylist. So at the end, i have an arraylist of one kind of objects. And all of these objects, also have an arraylist (and a few other values, like some strings and integers) with other objects.

The problem is that at the end, when i try to acces the arraylist inside one of these objects, its empty.

Dont know if what im trying to do in imposible. Ive declared both arraylists as arraylists of objects. Perhaps i should declare them as an arraylist of arraylists?

Thanks in advance.

Edited:

Would be something like this:

class Obj1 {
    String string;
    int integer;
    ArrayList objects2;

    public Obj1(String string, int integer, ArrayList objects2) {
        this.string = string;
        this.integer = integer;
        this.objects2 = objects2;
    }
}

This would be the first object (its ArrayList objects2, but "<>" doesnt appear).

class Obj2 {
    String string;
    int integer;

    public Obj2(String string, int integer2) {
        this.string = string;
        this.integer = integer;
    }
}

Same as before with the "<>"s.

Then, with an asynctask, i start to search from a webpage. I create some Ob2. I can have from 0 to maybe, 15. So if i get some, put all of them into an ArrayList of Objs2. Then i create an Obj1 and pass it its attributes string and integer, and the ArrayList of Objs2. And after, put this Obj1 into ArrayList of Objs1.

At the end, i can have for example, 12 Ojs1 into an ArrayList. And each one of these Obj1, have an ArrayList of Objs2, with 1 to 15 Objs2. What i return from the asynctask is the ArrayList of Objs1.

Hope you understand what i mean. Also my english wont help. hehe

Thanks again.

Edited 2:

private class DownloadWork extends AsyncTask<URL, String, List<Obj1>> {
    ArrayList<Obj1> objs1Downloaded = new ArrayList<Obj1>();
    ArrayList<Obj2> objs2Downloaded = new ArrayList<Obj2>();
    //Some more stuff
    protected List doInBackground(URL... params) {
    for(...) {
        //Do some stuff here ...
    }
    return objs1Downloaded;
}

That objs1Downloaded, as i said, would have 12 objs1 for example. And each obj1 could have an arraylist of objs2, with 1 to 15 obj2. Thats more or less the idea.

Thanks again and sorry for the edits and so.

link|improve this question

43% accept rate
3  
Can you update your question with the actual source code please? – dave.c Jan 26 '11 at 22:56
I added more code yesterday. Hope its more clear now. – user568288 Jan 27 '11 at 17:58
feedback

1 Answer

You should probably post some of your code to give us an idea, this shouldn't be any problem doing it like so:

class Inner {
    String name;
    int num;
    ArrayList<String> stringList;

    public Inner(String name, int num, ArrayList<String> items) {
        this.name = name;
        this.num = num;
        this.stringList = items;
    }
}

ArrayList<Inner> outerList = new ArrayList<Inner>();

ArrayList<String> innerList = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
    innerList.add("" + i);
}

outerList.add(new Inner("Name", 1, innerList));

This gives you one ArrayList containing a single inner object, which contains another ArrayList of Strings*.

*untested, general idea should be good.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.