android - Custom Adapter for a Gallery -
i've come across problem while writing custom adapter items on gallery. followed steps on android developer site, instead of returning imageview i'm returning textview. however, when try run application classcastexception when trying add child items gallery.
however if use basic string adapter gallery works, , if use imageview works too. don't problem since method
@override public view getview(int position, view convertview, viewgroup parent) return view base class both imageview , textview. don't possible wrong. know cause of problem?
thanks lot
this code of adapter,
public class historyindexadapter extends baseadapter { private context context; private arraylist<history> historyindex; private typeface typeface; public historyindexadapter(context context, arraylist<history> historyitems) { this.context = context; this.historyindex = historyitems; this.typeface = typeface.createfromasset(context.getassets(), context.getstring(r.string.font)); } @override public int getcount() { return historyindex.size(); } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { textview item = new textview(context); item.settext(historyindex.get(position).getdate()); item.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content)); item.settypeface(typeface); item.settextcolor(r.color.white); return item; } }
what qualified layoutparams class using? need use gallery.layoutparams. if don't, classcastexception.
Comments
Post a Comment