Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Doing this for an Android project; having issues creating An ArrayList out of what was formerly an Array of objects.

Here is what code WAS:

            MyReviewObject[] co = new MyReviewObject[reviews.size()];
            int index = 0;

            for (@SuppressWarnings("unused")
            String i : reviews) {
                co[index] = new MyReviewObject(datelist.get(index),
                        reviews.get(index), items.get(index),
                        cats.get(index));
                index++;
            }

            adapter = new MyReviewAdapter(getActivity(), co);
            setListAdapter(adapter);

Here is what I have now:

            ArrayList<MyReviewObject> co = new ArrayList<MyReviewObject>();


            for (String i : reviews) {
                co = new ArrayList<MyReviewObject>(datelist.add(i),reviews.add(i), items.add(i), cats.add(i));
            }

            adapter = new MyReviewAdapter(getActivity(), co);
            setListAdapter(adapter);

The statement in the for loop I am having hard time converting to make work? I know I am declaring the ArrayList twice and one should go.

EDIT:

here is Object:

public class MyReviewObject {
    public String comment;
    public String date;
    public String items;
    public String cat;

    public MyReviewObject(String s1, String s2, String s3, String s4) {
        this.date = s1;
        this.comment = s2;
        this.items = s3;
        this.cat = s4;

    }

}
share|improve this question

1 Answer 1

You don't need to create several arraylists, only several MyReviewObject:

for (String i : reviews) {
    MyReviewObject review = new MyReviewObject(datelist.get(i),
                    reviews.get(i), items.get(i),
                    cats.get(i));
    co.add(review);
}

ps: that assumes the original code works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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