Grouping Arraylist into Hashmap from Retrofit response By Date












0















I want to create section inside recyclerview, and i need to grouping response from retrofit by Date response. But i have problem about grouping arraylist into hashmap. Please share your answer if you has resolved problem like this.



Here my code



Object Class for handle retrofit respon



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_;
}
}


and here the main activity class who have retrofit request



 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();
}


i want to create section header inside recyclerview in adapter, and grouping the response by date.










share|improve this question



























    0















    I want to create section inside recyclerview, and i need to grouping response from retrofit by Date response. But i have problem about grouping arraylist into hashmap. Please share your answer if you has resolved problem like this.



    Here my code



    Object Class for handle retrofit respon



    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_;
    }
    }


    and here the main activity class who have retrofit request



     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();
    }


    i want to create section header inside recyclerview in adapter, and grouping the response by date.










    share|improve this question

























      0












      0








      0








      I want to create section inside recyclerview, and i need to grouping response from retrofit by Date response. But i have problem about grouping arraylist into hashmap. Please share your answer if you has resolved problem like this.



      Here my code



      Object Class for handle retrofit respon



      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_;
      }
      }


      and here the main activity class who have retrofit request



       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();
      }


      i want to create section header inside recyclerview in adapter, and grouping the response by date.










      share|improve this question














      I want to create section inside recyclerview, and i need to grouping response from retrofit by Date response. But i have problem about grouping arraylist into hashmap. Please share your answer if you has resolved problem like this.



      Here my code



      Object Class for handle retrofit respon



      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_;
      }
      }


      and here the main activity class who have retrofit request



       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();
      }


      i want to create section header inside recyclerview in adapter, and grouping the response by date.







      android arraylist android-recyclerview hashmap retrofit






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 2:52









      steven caesarsteven caesar

      228




      228
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404643%2fgrouping-arraylist-into-hashmap-from-retrofit-response-by-date%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404643%2fgrouping-arraylist-into-hashmap-from-retrofit-response-by-date%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$