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;

    }

}

Have you tried using select?

contex.Order.Load();
orderBindingSource.DataSource = 
   context.Order.Local().Select( m => m.customerID > 1).ToBindingList();

Edit

Not entirely sure about this, it compiles but I do not have a full environment to test it. Perhaps if you try to load in the specific data, and then you can access it in local for the binding list. Like this:

context.Order.Select( m => m.customerID > 1).Load();
orderBindingSource.DataSource = 
   context.Order.Local.ToBindingList();
4

1 回答 1

2

您不需要创建几个数组列表,只需几个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:假设原始代码有效。

于 2012-09-30T18:41:42.500 回答