如何将以前的列表数据添加到android中的新列表中

时间:2017-05-31 10:04:17

标签: java android

final ReviewItem reviewItem = (ReviewItem) responseBody;
final List reviewList = new ArrayList();//

ReviewHeaderItem header = new ReviewHeaderItem();
header.setTotalRatng(reviewItem.getAvg_rating());
header.setTotalReviews(reviewItem.getNum_reviews());
reviewList.add(header);
List<Reviews> lisOfReviews = reviewItem.getReviews();

List newReviewList=new ArrayList();


if (lisOfReviews.size() < 10) {
  reviewList.addAll(lisOfReviews);
  newReviewList.addAll(reviewList);

  } else {
    reviewList.addAll(lisOfReviews);

    newReviewList.addAll(reviewList);

    reviewList.add("");


  }

  configureList(reviewList);

  final ReviewItem reviewItem = (ReviewItem) responseBody;

我得到每个按钮点击的响应,我现在将它存储在列表中我想要的假设如果在第一次响应中我得到10条记录然后再次点击我又得到另外10条记录然后我想在之前的列表中添加它并且动态地我们必须添加它,请建议我如何实现它。

1 个答案:

答案 0 :(得分:0)

试试这个,我使用了处理程序,这样就可以延迟5秒了。在你的情况下,你必须在那里调用服务器

final List<String> reviewList = new ArrayList<>();
    final List<String> response1 = new ArrayList<>();
    final List<String> response2 = new ArrayList<>();
     response1.add("First");response1.add("Second");response1.add("Third");
            response2.add("Four");response2.add("Five");response2.add("Six");

            for (int i = 0; i < response1.size(); i++) {
                reviewList.add(response1.get(i));
            }
            Handler handler= new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < response2.size(); i++) {
                        reviewList.add(response2.get(i));
                    }

                }
            },500);

            Handler handler2= new Handler();
            handler2.postDelayed(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < reviewList.size(); i++) {
                        Log.v("@@@WWe"," "+reviewList.get(i));
                    }

                }
            },500);