How to set font type on android custombaseadapter -
i want change font type on list view, follow this answer,
i declare this
lv = (listview)findviewbyid(r.id.listview1); customadapter.custombaseadapter adapter = new customadapter.custombaseadapter(this, rowitems, "van helsing.ttf"); lv.setadapter(adapter); lv.setonitemclicklistener(this);
but nothing happen listview font, won't change.
this custom adapter:
public custombaseadapter(context context, list<rowitem> items, string font) { this.context = context; this.rowitems = items; tf = typeface.createfromasset(context.getassets(), font); }
what probelem codes guys ?
edited:
context context; list<rowitem> rowitems; typeface tf; public custombaseadapter(context context, list<rowitem> items, string font) { this.context = context; this.rowitems = items; tf = typeface.createfromasset(context.getassets(), font); } /*private view holder class*/ private class viewholder { textview txtmenu; } public view getview(int position, view convertview, viewgroup parent) { viewholder holder = null; layoutinflater minflater = (layoutinflater) context.getsystemservice(activity.layout_inflater_service); if (convertview == null) { convertview = minflater.inflate(r.layout.list_item, null); holder = new viewholder(); holder.txtmenu = (textview) convertview.findviewbyid(r.id.namamenu); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } rowitem rowitem = (rowitem) getitem(position); holder.txtmenu.settext(rowitem.getnamamenu()); holder.textmenu.settypeface(tf); return convertview; } @override public int getcount() { return rowitems.size(); } @override public object getitem(int position) { return rowitems.get(position); } @override public long getitemid(int position) { return rowitems.indexof(getitem(position)); }
my layout:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/namamenu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="#cc0033" android:textsize="32dp" android:textappearance="?android:attr/textappearancemedium" />
you need set font textview
of list item
textview.settypeface(tf);
tf instance of typeface
of custom font
example
@override public view getview(int position, view v, viewgroup parent) { view mview = v ; if(mview == null){ layoutinflater vi = (layoutinflater)mcontext.getsystemservice(context.layout_inflater_service); mview = vi.inflate(id, null); } textview text = (textview) mview.findviewbyid(r.id.textview); textview.settypeface(tf); } }
Comments
Post a Comment