android - Adapter not working with listview -
i want display icons in listview. here adapter
public class iconadapter extends baseadapter { private int[] iconlist; private context context; public iconadapter(int[] iconlist, context contex) { this.iconlist = iconlist; this.context = context; } @override public int getcount() { return 0; } @override public object getitem(int position) { return null; } @override public long getitemid(int position) { return 0; } @override public view getview(int position, view convertview, viewgroup parent) { imageview mimageview = new imageview(context); mimageview.setbackgroundresource(iconlist[position]); return mimageview; } }
this how set adapter
int[] iconlist = new int[]{r.drawable.ic_action_content_new, r.drawable.ic_color_lens_black_48dp}; holder.mlistview.setadapter(new iconadapter(iconlist, context));
the problem listview doesn't display anything
your getcount() method returns 0...
change to:
@override public int getcount() { return iconlist.length; } @override public object getitem(int position) { return iconlist[position]; } @override public long getitemid(int position) { return position; }
Comments
Post a Comment