java - Probelm with GridView using BaseAdapter in Android? -


i did gridview using baseadapter, having problem.

when scrolling gridview , down, on third or fourth time gridview deleted , left empty screen.

any suggestions on how resolve issue?

here code

adapterclass

public class booksadapter extends baseadapter {     string bookscategorylist[] =             {             "the world",             "food & drink",             "crime, mystery & thriller",             "science fiction & fantasy",             "family & health",             "music, stage & screen",             "language , linguistics",             "fiction",             "business & finance",             "time periods in history",             "special interest books",             "romance & erotica",             "children's books",             "biography",             "mind body & spirit",             "lifestyle, sport & leisure",             "sports",             "society & social sciences",             "art, architecture , photography",             "history & transport","medical",             "religion & spirituality",             "literature & literary studies",             "earth sciences, geography, environment & planning",             "graphic novels",             "humour",             "natural history & pets",             "hobbies & games",             "education"             };      int imagescategory[]=             {             r.mipmap.ic_launcher,r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher, r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher, r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher,r.mipmap.ic_launcher, r.mipmap.ic_launcher,             r.mipmap.ic_launcher,r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher,r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher, r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher,r.mipmap.ic_launcher, r.mipmap.ic_launcher,             r.mipmap.ic_launcher,r.mipmap.ic_launcher,r.mipmap.ic_launcher,             r.mipmap.ic_launcher                     };     context ctx;     public booksadapter(context context)     {         this.ctx = context;     }     @override     public int getcount() {         return imagescategory.length;     }      @override     public object getitem(int position) {         return imagescategory.length;     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent) {          viewholder holder;         layoutinflater inflater = (layoutinflater)ctx                 .getsystemservice(context.layout_inflater_service);         if (convertview == null)         {             convertview = inflater.inflate(r.layout.category_list_row, null);             holder = new viewholder();             holder.tvcategories = (textview) convertview.findviewbyid(r.id.tvcategory);             holder.ivcategories = (imageview) convertview.findviewbyid(r.id.ivcategories);             convertview.settag(holder);         }         else         {             holder = (viewholder) convertview.gettag();         }         holder.tvcategories.settext(bookscategorylist[position]);         holder.ivcategories.setimageresource(imagescategory[position]);          return convertview;     }      static class viewholder {         private textview tvcategories;         private imageview ivcategories;     } } 

my actvity class

public class categoryactivity extends activity {     imageview ivcategory;     gridview gvcategory;      @override     protected void oncreate(bundle savedinstancestate)  {         super.oncreate(savedinstancestate);         setcontentview(r.layout.categories_layout);           gvcategory = (gridview) findviewbyid(r.id.gvcategories);              booksadapter booksadapter = new booksadapter(categoryactivity.this);             gvcategory.setadapter(booksadapter);  } 

public class customadapter extends baseadapter {         context context;         imageloader loader;         arraylist<hashmap<string, string>> itemlist = new arraylist<hashmap<string, string>>();          public customadapter(context context,                 arraylist<hashmap<string, string>> itemlist) {             // todo auto-generated constructor stub             this.itemlist = itemlist;             this.context = context;             loader = new imageloader(context);         }          @override         public int getcount() {             // todo auto-generated method stub             return itemlist.size();         }          @override         public object getitem(int position) {             // todo auto-generated method stub             return itemlist.get(position);         }          @override         public long getitemid(int position) {             // todo auto-generated method stub             return position;         }          @override         public view getview(int position, view convertview, viewgroup parent) {             // todo auto-generated method stub             layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service);             view view = inflater.inflate(r.layout.product_item, parent, false);             imageview img = (imageview) view.findviewbyid(r.id.img_item);              textview tv = (textview) view.findviewbyid(r.id.text_item);             utility.setfont(tv, productlist.this);             display display = ((activity) productlist.this).getwindowmanager().getdefaultdisplay();             point size = new point();             display.getsize(size);             int width = size.x;             int height = size.y;              log.d("check", "width "+width);             log.d("check", "height "+height);             view.getlayoutparams().height=(int)(height/4);             view.getlayoutparams().width=(int)width/2;              loader.displayimage(utility.image_url+itemlist.get(position).get("image"),                     (activity) context, img);             tv.settext(itemlist.get(position).get("product_name"));             return view;         }      } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -