1

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;

    }

}
0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.