android - App Not Responding on click of image -


i working on application, , when click on image app stop responding. can't figure out issue is

below click listener cause app not responding

 holder.ivlike.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                      log.d("logfavourite", "like onclicklistener");                     log.e("loglike", "count: " + holder.tvnewscountlike.gettext().tostring());                      if (!utils.isnewslikedorfaved(context, postsdata, true)) {                          like(postsdata.getnews_id());                         utils.likeorfavnews(context, postsdata, true);     //                    notifydatasetchanged();                         holder.tvnewscountlike.settext("" + (integer.parseint(holder.tvnewscountlike.gettext().tostring()) + 1));                         holder.ivlike.setimageresource(r.drawable.dark);                     } else {                         unlike(postsdata.getnews_id());                         utils.unlikeorunfavnews(context, postsdata, true);     //                    notifydatasetchanged();                         holder.tvnewscountlike.settext("" + (integer.parseint(holder.tvnewscountlike.gettext().tostring()) - 1));                         holder.ivlike.setimageresource(r.drawable.light);                       }                  }             }); 

adapter class

    public class testnewsadapter extends realmbaserecyclerviewadapter<newstrend, testnewsadapter.postsviewholder> {          public realmresults<newstrend> realmresults;         public context context;         public eventlistener eventlistener;          retrofitinterface restapi;         static user user;         static  string fbid;          public testnewsadapter(context context, realmresults<newstrend> realmresults, boolean automaticupdate) {             super(context, realmresults, automaticupdate);             this.realmresults = realmresults;             this.context = context;         }          public void seteventlistener(eventlistener eventlistener) {             this.eventlistener = eventlistener;         }          @override         public postsviewholder oncreateviewholder(viewgroup viewgroup, int viewtype) {             user = trendingapplication.getinstance().getprefmanager().getuser();              fbid = user.getid();             view v = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.row_news, viewgroup, false);             postsviewholder mediaviewholder = new postsviewholder(v);             return mediaviewholder;         }          @override         public void onbindviewholder(final postsviewholder holder, int position) {              final newstrend postsdata = getitem(position);              if (position % 2 == 1) {                 holder.llleft.setgravity(gravity.right);                 holder.llright.setgravity(gravity.left);                 holder.ivarrowleft.setvisibility(view.invisible);                 holder.ivarrowright.setvisibility(view.visible);             }              string eventname = postsdata.gettitle();             string eventdate = postsdata.gettimestamp();             holder.sourcename.settext(postsdata.gettype());              if (utils.isnewslikedorfaved(context, postsdata, true)) {                 holder.ivlike.setimageresource(r.dark);             } else {                 holder.ivlike.setimageresource(r.drawable.light);             }              if (utils.isnewslikedorfaved(context, postsdata, false)) {                 holder.ivfavorite.setimageresource(r.drawable.dark_fav);             } else {                 holder.ivfavorite.setimageresource(r.drawable.light_fav);             }              spanned decodedtitle = html.fromhtml(eventname);              if(postsdata.gettype().equals("bella naija")){                 holder.sourceimg.setimageresource(r.drawable.bella);             }else if(postsdata.gettype().equals("punch")){                 holder.sourceimg.setimageresource(r.drawable.punch);             }else if(postsdata.gettype().equals("linda ikeji")){                 holder.sourceimg.setimageresource(r.drawable.lib);             }else if(postsdata.gettype().equals("pulse")){                 holder.sourceimg.setimageresource(r.drawable.pulse_logo);             }               holder.tvcountpageview.settext(postsdata.getread_count() + " views");             holder.tvnewscountlike.settext("" + postsdata.getlike_count());              holder.tvnewstitle.settext(decodedtitle);             holder.tvnewsdate.settext(getsplitdate(eventdate));             string text = postsdata.getcontent() + "<font color='red'>  <strong>more...</strong></font>";             holder.tvnewsshorttext.settext(html.fromhtml(text), textview.buffertype.spannable);            // holder.sourcename.settext(postsdata.gettype());                   glide.with(context)                         .load(postsdata.getimage())                         .centercrop()                         .placeholder(r.drawable.tw_logo)                         .into(holder.ivnewsimage);               holder.llright.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(final view v) {                     sendreadinfo(postsdata.getnews_id());                     /*intent in = new intent(context, webviewactivity.class);                     in.putextra(webviewactivity.arg_search_request, postsdata.gethref());                     context.startactivity(in);*/                     new finestwebview.builder(context)                             .theme(r.style.finestwebviewtheme)                             .titledefault("what's trending")                             .showurl(false)                             .statusbarcolorres(r.color.blueprimarydark)                             .toolbarcolorres(r.color.colorprimary)                             .titlecolorres(r.color.finestwhite)                             .urlcolorres(r.color.colorprimarydark)                             .icondefaultcolorres(r.color.finestwhite)                             .progressbarcolorres(r.color.primarydarkcolor)                             .stringrescopiedtoclipboard(r.string.copied_to_clipboard)                             .stringrescopiedtoclipboard(r.string.copied_to_clipboard)                             .stringrescopiedtoclipboard(r.string.copied_to_clipboard)                             .showswiperefreshlayout(true)                             .swiperefreshcolorres(r.color.blueprimarydark)                             .menuselector(r.drawable.selector_light_theme)                             .menutextgravity(gravity.center)                             .menutextpaddingrightres(r.dimen.defaultmenutextpaddingleft)                             .dividerheight(0)                             .gradientdivider(false)                             .setcustomanimations(r.anim.slide_up, r.anim.hold, r.anim.hold, r.anim.slide_down)                             .show(postsdata.gethref());                 }             });              holder.ivshare.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                      string sharebody =  postsdata.gethref();                      intent sharingintent = new intent(android.content.intent.action_send);                     sharingintent.settype("text/plain");                     sharingintent.putextra(android.content.intent.extra_subject, "trending app");                     sharingintent.putextra(android.content.intent.extra_text, sharebody);                     context.startactivity(intent.createchooser(sharingintent, "paylaş"));                 }             });               /*holder.ivfavorite.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                      log.d("logfavourite", "like onclicklistener");                       if (!utils.isnewslikedorfaved(context, postsdata, false)) {                         utils.likeorfavnews(context, postsdata, false);                         notifydatasetchanged();                      } else {                         utils.unlikeorunfavnews(context, postsdata, false);                         notifydatasetchanged();                     }                  }             });*/             holder.ivlike.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                      log.d("logfavourite", "like onclicklistener");                     log.e("loglike", "count: " + holder.tvnewscountlike.gettext().tostring());                      if (!utils.isnewslikedorfaved(context, postsdata, true)) {                          like(postsdata.getnews_id());                         utils.likeorfavnews(context, postsdata, true);     //                    notifydatasetchanged();                         holder.tvnewscountlike.settext("" + (integer.parseint(holder.tvnewscountlike.gettext().tostring()) + 1));                         holder.ivlike.setimageresource(r.drawable.kalp_dolu_kucuk);                     } else {                         unlike(postsdata.getnews_id());                         utils.unlikeorunfavnews(context, postsdata, true);     //                    notifydatasetchanged();                         holder.tvnewscountlike.settext("" + (integer.parseint(holder.tvnewscountlike.gettext().tostring()) - 1));                         holder.ivlike.setimageresource(r.drawable.kalp_bos_kucuk);                       }                  }             });            }          private void like(final int newsitemid) {             setuprestclient();             log.e("logfb", "hunk" + fbid);             restapi.like(newsitemid, fbid, new callback<readstatus>() {                 @override                 public void success(readstatus readstatus, response response) {                     log.e("loglike", "liked, id:" + newsitemid);                 }                  @override                 public void failure(retrofiterror error) {                     log.e("loglike", "fail like");                  }             });          }          private void unlike(final int newsitemid) {             setuprestclient();              restapi.unlike(newsitemid, fbid, new callback<readstatus>() {                 @override                 public void success(readstatus readstatus, response response) {                     log.e("loglike", "unliked, id:" + newsitemid);                 }                  @override                 public void failure(retrofiterror error) {                     log.e("loglike", "fail unlike");                  }             });          }          private void setuprestclient() {             restadapter.builder builder = new restadapter.builder()                     .setendpoint("http://voice.atp-sevas.com")                     .setclient(new okclient(new okhttpclient()))                     .setloglevel(restadapter.loglevel.full);              restadapter restadapter = builder.build();              restapi = restadapter.create(retrofitinterface.class);         }          private void sendreadinfo(int id) {             setuprestclient();              restapi.sendreadinfo(id, fbid, new callback<readstatus>() {                 @override                 public void success(readstatus readstatus, response response) {                     log.d("logread", "send info send: " + readstatus.issuccess());                  }                  @override                 public void failure(retrofiterror error) {                     log.d("logread", "send info failed");                  }             });         }          @override         public newstrend getitem(int i) {             return realmresults.get(i);         }          public void swapdata(realmresults<newstrend> realmresults) {             this.realmresults = realmresults;             notifydatasetchanged();         }          @override         public void onattachedtorecyclerview(recyclerview recyclerview) {             super.onattachedtorecyclerview(recyclerview);         }          @override         public int getitemcount() {             return realmresults.size();         }          public static class postsviewholder extends recyclerview.viewholder {              public textview tvnewsdate;             public textview tvnewstitle;             public textview tvnewsshorttext;             public textview sourcename;             public imageview sourceimg;              relativelayout postcontentholder;                public linearlayout llleft;             public linearlayout llright;              public imageview ivarrowleft;             public imageview ivarrowright;              public imageview ivnewsimage;              public imageview ivshare;              public imageview ivfavorite;             public imageview ivlike;              public textview tvcountpageview;             public textview tvnewscountlike;              postsviewholder(view itemview) {                 super(itemview);                 postcontentholder = (relativelayout) itemview.findviewbyid(r.id.postcontentholder);                 ivnewsimage = (imageview) itemview.findviewbyid(r.id.ivnewsimage);                 ivarrowleft = (imageview) itemview.findviewbyid(r.id.ivarrowleft);                 ivarrowright = (imageview) itemview.findviewbyid(r.id.ivarrowright);                 llleft = (linearlayout) itemview.findviewbyid(r.id.llleft);                 llright = (linearlayout) itemview.findviewbyid(r.id.llright);                  ivshare = (imageview) itemview.findviewbyid(r.id.ivshare);                 sourceimg = (imageview) itemview.findviewbyid(r.id.sourceimg);                 sourcename = (textview) itemview.findviewbyid(r.id.sourcename);                 tvnewstitle = (textview) itemview.findviewbyid(r.id.tvnewstitle);                 tvnewsshorttext = (textview) itemview.findviewbyid(r.id.tvnewsshorttext);                 tvnewsdate = (textview) itemview.findviewbyid(r.id.tvnewsdate);                  ivfavorite = (imageview) itemview.findviewbyid(r.id.ivfavorite);                 ivlike = (imageview) itemview.findviewbyid(r.id.ivlike);                  tvnewscountlike = (textview) itemview.findviewbyid(r.id.tvnewscountlike);                 tvcountpageview = (textview) itemview.findviewbyid(r.id.tvcountpageview);              }         }          public interface eventlistener {             void onitemclick(final view view, newstrend postsdata);         }          @override         public int getitemviewtype(int position) {             return position;         }          public string getsplitdate(string datestring){              return datestring;         }           public string getsmalldescp(string descp){             string text = descp + "<font color='#f2732f'>  <strong>more...</strong></font>";              return text.substring(0, 50);         }      } 

util.class

  public class utils {          public static boolean isnewslikedorfaved(context context, newstrend newsitem, boolean isliked) {              arraylist<newstrend> newsitems = getlikedorfavednews(context, isliked);              if (newsitems != null) {                   (newstrend news : newsitems) {                      if (newsitem.getnews_id() == news.getnews_id()) {                         log.d("logfavourite", "isnewslikedorfaved true newsitem.getid: " + newsitem.getnews_id() + ", news.getid: " + news.getnews_id());                          return true;                     }                 }             }              log.d("logfavourite", "isnewslikedorfaved false");              return false;          }           public static void likeorfavnews(context context, newstrend newsitem, boolean islike) {              log.d("logfavourite", "likenews");              sharedpreferences preferences = context.getsharedpreferences("prefs", context.mode_private);              string jsonlikednews;             if (islike)                 jsonlikednews = preferences.getstring("likednews", null);             else                 jsonlikednews = preferences.getstring("favednews", null);               if (jsonlikednews != null) {                 arraylist<newstrend> newsitems = converttomodel(jsonlikednews);     //            newsitem.setlikecount(newsitem.getlikecount() + 1);                 newsitems.add(newsitem);                  log.d("logfavourite", "size: " + newsitems.size());                 string jsonupdatedlikednews = converttojson(newsitems);                  sharedpreferences.editor editor = preferences.edit();                 if (islike)                     editor.putstring("likednews", jsonupdatedlikednews);                 else                     editor.putstring("favednews", jsonupdatedlikednews);                  editor.commit();             } else {                  arraylist<newstrend> newsitems = new arraylist<>();                 newsitems.add(newsitem);                  log.d("logfavourite", "size: " + newsitems.size());                 string jsonupdatedlikednews = converttojson(newsitems);                  sharedpreferences.editor editor = preferences.edit();                 if (islike)                     editor.putstring("likednews", jsonupdatedlikednews);                 else                     editor.putstring("favednews", jsonupdatedlikednews);                  editor.commit();               }          }          public static void unlikeorunfavnews(context context, newstrend newsitem, boolean islike) {              log.d("logfavourite", "likenews");              sharedpreferences preferences = context.getsharedpreferences("prefs", context.mode_private);              string jsonlikednews;             if (islike)                 jsonlikednews = preferences.getstring("likednews", null);             else                 jsonlikednews = preferences.getstring("favednews", null);              if (jsonlikednews != null) {                 arraylist<newstrend> newsitems = converttomodel(jsonlikednews);                  (int = 0; < newsitems.size(); i++) {                      if (newsitems.get(i).getnews_id() == newsitem.getnews_id())                         newsitems.remove(i);                  }                  log.d("logfavourite", "size: " + newsitems.size());                   string jsonupdatedlikednews = converttojson(newsitems);                  sharedpreferences.editor editor = preferences.edit();                 if (islike)                     editor.putstring("likednews", jsonupdatedlikednews);                 else                     editor.putstring("favednews", jsonupdatedlikednews);                  editor.commit();             }          }          public static arraylist<newstrend> getlikedorfavednews(context context, boolean islike) {              sharedpreferences preferences = context.getsharedpreferences("prefs", context.mode_private);             string jsonlikednews;             if (islike)                 jsonlikednews = preferences.getstring("likednews", null);             else                 jsonlikednews = preferences.getstring("favednews", null);              arraylist<newstrend> newsitems;             if (jsonlikednews != null) {                 newsitems = converttomodel(jsonlikednews);             } else {                 newsitems = new arraylist<>();             }             return newsitems;           }          public static string converttojson(arraylist<newstrend> newsitems) {             gson gson = new gson();             string json = gson.tojson(newsitems);             return json;         }          public static arraylist<newstrend> converttomodel(string jsonstring) {             gson gson = new gson();             newstrend[] newsitems = gson.fromjson(jsonstring, newstrend[].class);             arraylist<newstrend> newsitemlist = new arraylist<>();              (int = 0; < newsitems.length; i++) {                 newsitemlist.add(newsitems[i]);             }             return newsitemlist;         }              public static string converttonewsjson(newstrend news) {             gson gson = new gson();             string json = gson.tojson(news);             return json;         }          public static newstrend converttonewsmodel(string jsonstring) {             gson gson = new gson();             newstrend news = gson.fromjson(jsonstring, newstrend.class);             return news;         }       } 


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -