android - Listview weird reaction on Clicking -


i'm displaying listview custom adapter. each item of list view has photo (imageview) , (flipimageview) button , textview show number of likes. have populated listview 3 items. weird issue when click on button of second photo, there no response (no flipping of image , no change in number of likes). instead first photo button responds , number of likes of first photo got incremented. second weird issue that, first item of listview isn't populated (an imageview lies blank while imageview of other list items inflate fully). when scroll , come first item, gets inflated fully. here adapter code, xml file of each list item, , listview itself. how solve these issues?

class postadapter extends arrayadapter<eachpost>  {   arraylist<eachpost> posts;   viewholder vholder;   string root = environment.getexternalstoragedirectory().tostring();   file dir = new file (root + "/fishograph/.feed");     public postadapter(context context, int resource, arraylist<eachpost> list) {         super(context, r.layout.postcontent, list);         posts = list;     }     @override     public view getview(int pos,view vu,viewgroup vg)     {       final eachpost post = posts.get(pos);       final int finalpos = pos;       final string han = post.gethandle();       final string imgurl = post.getdpbase64();        if(vu == null)       {          vu = getactivity().getlayoutinflater().inflate(r.layout.postcontent,vg,false);          vholder = new viewholder();         vholder.handle = ((textview) vu.findviewbyid(r.id.handle));         vholder.caption = ((textview) vu.findviewbyid(r.id.caption));         vholder.likesnum = ((textview) vu.findviewbyid(r.id.likesnum));         vholder.comnum = ((textview) vu.findviewbyid(r.id.comnum));         vholder.uploadtime = ((textview) vu.findviewbyid(r.id.uploadtime));         vholder.photo = (imageview) vu.findviewbyid(r.id.imgpost);         vholder.feeddp = (imageview) vu.findviewbyid(r.id.realdp);         vholder.like = (flipimageview) vu.findviewbyid(r.id.like);         drawable d =getresources().getdrawable(r.drawable.hook_like);         vholder.like.setflippeddrawable(d);         layoutparams lp = vholder.photo.getlayoutparams();         lp.width = width;         lp.height = width;         vholder.feeddp.requestlayout();         vholder.like.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                  // todo auto-generated method stub                 if(!likes.contains(imgurl))                    {                     requestparams rp = new requestparams();                     rp.add("handle",handle);                     rp.add("url",imgurl);                     vholder.like.toggleflip();                     new asynchttpclient().post("php script increment like",rp,new asynchttpresponsehandler(){                         @override                         public void onfailure(int code,throwable t,string err)                         {                             toast.maketext(getactivity(), "something went wrong..please try again", toast.length_short).show();                             log.d("onerror like",err);                             vholder.like.toggleflip();                         }                         @override                         public void onsuccess(string response)                         {                             response = response.trim();                             log.d("like", response);                             if(!response.equals("liked"))                                 {                                   toast.maketext(getactivity(), "something went wrong..please try again", toast.length_short).show();                                  vholder.like.toggleflip();                                 }                             else                                 { likes.add(imgurl);                                   post.incrementlikes();                                   vholder.likesnum.settext(post.getlikes()+"");                                 }                         }                     });                   }                 else                   {                     requestparams rp = new requestparams();                     rp.add("handle",handle);                     rp.add("url", imgurl);                     vholder.like.toggleflip();                     new asynchttpclient().post("php script url unlike",rp,new asynchttpresponsehandler(){                         @override                         public void onfailure(int code,throwable t,string err)                         {                             toast.maketext(getactivity(), "something went wrong..please try again", toast.length_short).show();                             log.d("onerror unlike", err);                             vholder.like.toggleflip();                         }                         @override                         public void onsuccess(string response)                         {                             response = response.trim();                             log.d("unlike", response);                             if(!response.equals("unliked"))                                 {                                  toast.maketext(getactivity(), "something went wrong..please try again", toast.length_short).show();                                  vholder.like.toggleflip();                                 }                             else                                 {                                   likes.remove(imgurl);                                  post.decrementlikes();                                  vholder.likesnum.settext(post.getlikes()+"");                                 }                         }                     });                   }             }         });         vu.settag(vholder);       }       else       vholder = (viewholder) vu.gettag();          vholder.handle.settext(posts.get(pos).gethandle());         vholder.caption.settext(posts.get(pos).getcaption());         vholder.likesnum.settext(posts.get(pos).getlikes()+"");         vholder.comnum.settext(posts.get(pos).getcomments()+"");         vholder.uploadtime.settext(posts.get(pos).getul());         glide.with(getactivity()).load("photo load").into(vholder.photo);         requestparams rpdp = new requestparams();         log.d("feed postadapter load dp handle", han);         rpdp.add("handle",han);         new asynchttpclient().post("url dp of user", rpdp, new asynchttpresponsehandler(){             @override             public void onsuccess(string response)             {                response = response.trim();               log.d("getdpurl",finalpos+response);               if(response.contains("http"))                   glide.with(getactivity()).load(response).into(vholder.feeddp);               else                   glide.with(getactivity()).load("url of dp").into(vholder.feeddp);             }             @override             public void onfailure(int err,throwable error,string response)             {               log.d("feed postadapter getdpurl", response);             }         });          requestparams rpliked = new requestparams();         rpliked.add("handle", handle);         rpliked.add("url",imgurl);         new asynchttpclient().post("php script check if photo likes", rpliked, new asynchttpresponsehandler(){             @override             public void onsuccess(string response)             {                response = response.trim();               log.d("feed postadapter isliked", response);               if(response.equals("islikedyes"))               { //todo set hook-like                 likes.add(imgurl);                 vholder.like.setflipped(true, false);               }             }             @override             public void onfailure(int err,throwable error,string response)             {              log.d("feed postadapter isliked", response);              //toast.maketext(getactivity(), response, toast.length_short).show();               }         });              return vu;     }      @override     public boolean isenabled(int position)     {         return true;     } } 

listview each item

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <framelayout android:id="@+id/dpsmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginleft="2dp"> <imageview     android:id="@+id/realdp"     android:layout_width="30dp"     android:layout_height="30dp"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:scaletype="centercrop"     android:adjustviewbounds="true"/> <imageview     android:id="@+id/trans"     android:layout_width="30dp"     android:layout_height="30dp"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:scaletype="fitxy"     android:adjustviewbounds="true"     android:src="@drawable/framedo" /> </framelayout>  <textview     android:id="@+id/handle"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_torightof="@+id/dpsmall"     android:text="handle"     android:layout_marginleft="3dp"     android:gravity="center_vertical"     android:layout_aligntop="@+id/dpsmall"     android:layout_alignbottom="@+id/dpsmall"     android:textappearance="?android:attr/textappearancemedium" />  <textview     android:id="@+id/uploadtime"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbaseline="@+id/handle"     android:layout_marginright="5dp"     android:layout_alignparentright="true"     android:text="time"     android:textappearance="?android:attr/textappearancesmall" />     <relativelayout android:id="@+id/rlimg"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_below="@+id/handle"   android:layout_margintop="5dp"   android:layout_marginbottom="5dp"   > <imageview     android:id="@+id/imgpost"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:scaletype="fitxy"     android:adjustviewbounds="true"     android:background="#ffffff"     android:layout_margintop="7dp"      />  </relativelayout> <com.sivaram.fishograph.flipimageview     xmlns:fiv="http://schemas.android.com/apk/res-auto"     android:id="@+id/like"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/rlimg"     android:background="#00000000"     android:layout_marginleft="40dp"     android:src="@drawable/hook_unlike"/>  <imagebutton     android:id="@+id/comment"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/rlimg"     android:background="#00000000"     android:layout_torightof="@+id/likesnum"     android:layout_marginleft="5dp"     android:src="@drawable/comment" /> <imagebutton     android:id="@+id/more"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/rlimg"     android:layout_marginright="3dp"     android:layout_alignparentright="true"     android:background="#00000000"     android:src="@drawable/more" />  <textview     android:id="@+id/likesnum"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/like"     android:layout_aligntop="@+id/like"     android:layout_marginleft="2dp"     android:layout_torightof="@+id/like"     android:text="likes"     android:gravity="center_vertical"     android:textappearance="?android:attr/textappearancemedium"     android:textcolor="#440011" />  <textview     android:id="@+id/comnum"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/comment"     android:layout_aligntop="@+id/comment"     android:layout_marginleft="2dp"     android:layout_torightof="@+id/comment"     android:gravity="center_vertical"     android:text="comments"     android:textappearance="?android:attr/textappearancemedium"     android:textcolor="#440011" />  <textview     android:id="@+id/caption"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/rlimg"     android:layout_below="@+id/like"     android:layout_margintop="10dp"     android:paddingleft="5dp"     android:paddingright="5dp"     android:layout_marginbottom="20dp"     android:gravity="center"     android:text="caption"     android:textappearance="?android:attr/textappearancemedium" /> </relativelayout> 

the listview itself

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:clickable="false" android:descendantfocusability="blocksdescendants" android:focusable="false" android:focusableintouchmode="false" >  <listview     android:id="@+id/lvposts"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:divider="#55ea4f5f"     android:listselector="#00000000"     android:clickable="false"     android:smoothscrollbar="true"     android:scrollingcache="false"     android:animationcache="false" > </listview> </linearlayout> 

i remove these final declarations. populating them value of first item:

final eachpost post = posts.get(pos); final int finalpos = pos; final string han = post.gethandle(); final string imgurl = post.getdpbase64() 

to:

eachpost post = posts.get(pos); int finalpos = pos; string han = post.gethandle(); string imgurl = post.getdpbase64() 

you should see change in log.d("getdpurl",finalpos+response); when this. please let me know if doesn't solve problem.

there quite bit of info on over web.. here's one

can change value of final int


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -