按日期将阵列列表从改造响应分组到Hashmap中

时间:2018-11-21 02:52:06

标签: android arraylist android-recyclerview hashmap retrofit

我想在recyclerview内创建部分,我需要按Date响应对改造响应进行分组。但是我有关于将arraylist分组为hashmap的问题。如果您已解决了此类问题,请分享您的答案。

这是我的代码

用于手柄改造响应的对象类

public class ContentSetget {

String Title_ ;
String Content_ ;
String Excerpt_ ;
String Date_ ;
String MediaId ;
String Author_ ;



public void setTitle_(String title_) {
    Title_ = title_;
}

public void setContent_(String content_) {
    Content_ = content_;
}

public void setExcerpt_(String excerpt_) {
    Excerpt_ = excerpt_;
}

public void setDate_(String date_) {
    Date_ = date_;
}

public void setMediaId(String mediaId) {
    MediaId = mediaId;
}

public void setAuthor_(String author_) {
    Author_ = author_;
}

public String getTitle_() {
    return Title_;
}

public String getContent_() {
    return Content_;
}

public String getExcerpt_() {
    return Excerpt_;
}

public String getDate_() {
    return Date_;
}

public String getMediaId() {
    return MediaId;
}

public String getAuthor_() {
    return Author_;
}
 }

这里是需要改装的主要活动类别

 public void getOutlook(){

    new Thread(new Runnable() {
        @Override
        public void run() {

            apiInterface = RetrofitClient.getClient().create(ApiInterface.class);
            Call<List<WpPost>> call = apiInterface.getOutlookNews();
            call.enqueue(new Callback<List<WpPost>>() {

                @Override
                public void onResponse(Call<List<WpPost>> call, Response<List<WpPost>> response) {
                    if(response.isSuccessful()){
                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                progressBar.setVisibility(View.GONE);

                            }
                        });

                        for ( i =0; i < response.body().size();i++) {

                            Media_id = response.body().get(i).getFeatured_image_src();
                            String date_ = response.body().get(i).getDate();
                            date_ = date_.replace("T", " ");
                            String newDate = formatDate(date_);
                            String title_ = response.body().get(i).getTitle().getRendered();
                            String content_ = response.body().get(i).getContent().getRendered();
                            int author = response.body().get(i).getAuthor();
                            String authorName = getAuthor.getName(author);


                            ContentSetget model = new ContentSetget();
                            model.setTitle_(title_);
                            model.setContent_(content_);
                            model.setDate_(newDate);
                            model.setMediaId(Media_id);
                            model.setAuthor_(authorName);
                            list_content.add(model);

                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                outlookAdapter = new OutlookAdapter(OutlookActivity.this, list_content);
                                outlookAdapter.notifyDataSetChanged();
                                recyclerView.setAdapter(outlookAdapter);
                            }
                        });
                        }
                }else{
                    int statusCode = response.code();
                    Log.e("Error Response","Code "+statusCode);
                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                progressBar.setVisibility(View.GONE);

                            }
                        });
                }
            }
                @Override
                public void onFailure(Call<List<WpPost>> call, Throwable t) {
                    Log.e("Response", "Error: " + t.getMessage());
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.GONE);

                        }
                    });
                }
            });

            }
    }).start();
}

我想在适配器的recyclerview内部创建节标题,并按日期对响应进行分组。

0 个答案:

没有答案