Display Repeatation Item in ListView after three Item on Scrolling in android? -


i want fill listview but repeat imglike,imgcomments,txtlikeunlike , txtcomments items. because using array imglike,imgcomments,txtlikeunlike , txtcomments (fetch)selected position. mistake in code please guide me.

my code, /** adapter class */

public class adapter1 extends baseadapter {         imageview imgimage = null,imgunlike[] = null, imglike[] = null,imgcomments[] = null, imgshare[] = null;         textview txtid = null,txtlikeunlike[] = null, txtcomments[] = null;               public arraylist<hashmap<string, string>> arr = null;             context context = null;             layoutinflater layoutinflater = null;             hashmap<string, string> getdata = new hashmap<string, string>();              public adapter1(context context,                     arraylist<hashmap<string, string>> arr) {                  this.context = context;                 this.arr = arr;                 layoutinflater = layoutinflater.from(context);                 this.imgunlike = new imageview[arr.size()];                 this.imglike = new imageview[arr.size()];                 this.imgcomments = new imageview[arr.size()];                 this.imgshare = new imageview[arr.size()];                 this.txtlikeunlike = new textview[arr.size()];                 this.txtcomments = new textview[arr.size()];             }              @override             public int getcount() {                 return arr.size();             }              @override             public object getitem(int position) {                 return arr.get(position);             }              @override             public long getitemid(int position) {                 return position;             }              @suppresslint("inflateparams")             @override             public view getview(final int position, view convertview,                     viewgroup parent) {                 view row = null;                 if (convertview == null) {                     layoutinflater inflater = ((activity) context)                             .getlayoutinflater();                     row = inflater.inflate(r.layout.list_item, parent,                             false);                 } else {                      row = convertview;                 }                 /** initialize widgets */                 /** imageview */                  imgimage = (imageview) row                         .findviewbyid(r.id.imgimage);                  imgunlike[position] = (imageview) row                         .findviewbyid(r.id.imgunlike);                  imglike[position] = (imageview) row                         .findviewbyid(r.id.imglike);                  imgcomments[position] = (imageview) row                         .findviewbyid(r.id.imgcomments);                  imgshare[position] = (imageview) row                         .findviewbyid(r.id.imgshare);                  /** textview */                 txttid = (textview) row                         .findviewbyid(r.id.txtid);                 txtlikeunlike[position] = (textview) row                         .findviewbyid(r.id.txtlikeunlike);                 txtcomments[position] = (textview) row                         .findviewbyid(r.id.txtcomments);                  getdata = arr.get(position);                  txtid.settext(getdata.get(fragment1.tag_id));                  imgunlike[position]                         .setonclicklistener(new onclicklistener() {                              @override                             public void onclick(view v) {                                 imgunlike[position]                                         .setvisibility(view.invisible);                                 imglike[position]                                         .setvisibility(view.visible);                                  getcurrentposition = position;                             }                         });                  imglike[position].setonclicklistener(new onclicklistener() {                      @override                     public void onclick(view v) {                         imgnewsfeedlike[position].setvisibility(view.invisible);                         imgnewsfeedunlike[position].setvisibility(view.visible);                      }                 });                  row.setonclicklistener(new onclicklistener() {                     @override                     public void onclick(view v) {                          intent intent = new intent(getactivity(),                                 detail.class);                         startactivity(intent);                     }                 });                 return row;             } 

xml file is,

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/masterlayout"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_margin="@dimen/five_dp" >      <imageview         android:id="@+id/imgimage"         android:layout_width="fill_parent"         android:layout_height="150dp"         android:layout_below="@+id/imgbluestrip"         android:layout_centerhorizontal="true"         android:layout_margin="10dp"         android:background="@null"         android:contentdescription="@string/content_description"         android:src="@drawable/ic_launcher" />      <linearlayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@+id/imgimage"         android:background="@drawable/strip"         android:baselinealigned="false"         android:gravity="center_vertical"         android:orientation="horizontal" >          <relativelayout             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_weight="1" >              <imageview                 android:id="@+id/imgunlike"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centerhorizontal="true"                 android:layout_centerinparent="true"                 android:contentdescription="@string/content_description"                 android:src="@drawable/unlike" />              <imageview                 android:id="@+id/imglike"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centerhorizontal="true"                 android:layout_centervertical="true"                 android:contentdescription="@string/content_description"                 android:src="@drawable/like"                 android:visibility="invisible" />              <textview                 android:id="@+id/txtlikeunlike"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignparenttop="true"                 android:layout_marginleft="2dp"                 android:layout_torightof="@+id/imgunlike"                 android:background="@drawable/get_notification_bg"                 android:gravity="center"                 android:padding="2dp"                 android:textcolor="@color/white"                 android:textsize="10sp" />         </relativelayout>          <relativelayout             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_weight="1" >              <imageview                 android:id="@+id/imgcomments"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centerhorizontal="true"                 android:layout_centerinparent="true"                 android:contentdescription="@string/content_description"                 android:src="@drawable/comments" />              <textview                 android:id="@+id/txtcomments"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_torightof="@+id/imgcomments"                 android:background="@drawable/get_"                 android:gravity="center"                 android:padding="2dp"                 android:textcolor="@android:color/white"                 android:textsize="10sp" />         </relativelayout>          <relativelayout             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_weight="1" >              <imageview                 android:id="@+id/imgshare"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centerhorizontal="true"                 android:layout_centerinparent="true"                 android:contentdescription="@string/content_description"                 android:src="@drawable/share" />         </relativelayout>     </linearlayout>      <textview         android:id="@+id/txtid"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="10dp"         android:text="id" />      <imageview         android:id="@+id/imgbluestrip"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_below="@+id/txtid"         android:contentdescription="@string/content_description"         android:src="@drawable/blue_strip" />  </relativelayout> 

my layout display this,enter image description here


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -