android - custom font (unicode) in Custom ListView Adapter doesn't show -
i want create custom list adapter unicode. code , compiles without errors unicode characters didn't show. please me rectify problem. you.
customlistviewadapter
package com.theopentutorials.android.beans; import java.util.list; import com.theopentutorials.android.r; import com.theopentutorials.android.beans.rowitem; import android.app.activity; import android.content.context; import android.graphics.typeface; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.imageview; import android.widget.textview; public class customlistviewadapter extends arrayadapter<rowitem> { context context; public customlistviewadapter(context context, int resourceid, list<rowitem> items) { super(context, resourceid, items); this.context = context; } /* private view holder class */ private class viewholder { imageview imageview; textview txttitle; textview txtdesc; } public view getview(int position, view convertview, viewgroup parent) { viewholder holder = null; rowitem rowitem = getitem(position); layoutinflater minflater = (layoutinflater) context .getsystemservice(activity.layout_inflater_service); if (convertview == null) { convertview = minflater.inflate(r.layout.list_item, null); holder = new viewholder(); holder.txtdesc = (textview) convertview.findviewbyid(r.id.desc); holder.txttitle = (textview) convertview.findviewbyid(r.id.title); holder.imageview = (imageview) convertview.findviewbyid(r.id.icon); convertview.settag(holder); } else holder = (viewholder) convertview.gettag(); holder.txtdesc.settext(rowitem.getdesc()); holder.txttitle.settext(rowitem.gettitle()); holder.imageview.setimageresource(rowitem.getimageid()); return convertview; } }
imagetextlistviewactivity
package com.theopentutorials.android.beans; import java.util.arraylist; import java.util.list; import com.theopentutorials.android.r; import android.app.activity; import android.graphics.typeface; import android.os.bundle; import android.view.gravity; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.edittext; import android.widget.listview; import android.widget.toast; public class imagetextlistviewactivity extends activity implements onitemclicklistener { public static final string[] titles = new string[] { "කළමනාකාරීත්වයක්", "පරිසරයට", "සමාගම ", "xxxxxx " }; public static final string[] descriptions = new string[] { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccc", "dddddddddddddddddddddddddddddd" }; public static final integer[] images = { r.drawable.straw, r.drawable.banana, r.drawable.orange, r.drawable.mixed }; listview listview; list<rowitem> rowitems; public typeface mytypeface; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mytypeface = typeface .createfromasset(getassets(), "fonts/iskpotab.ttf"); edittext edt1 = (edittext) findviewbyid(r.id.edittext1); edt1.settext("කළමනාකාරීත්වයක්"); edt1.settypeface(mytypeface); rowitems = new arraylist<rowitem>(); (int = 0; < titles.length; i++) { rowitem item = new rowitem(images[i], titles[i], descriptions[i]); rowitems.add(item); } listview = (listview) findviewbyid(r.id.list); customlistviewadapter adapter = new customlistviewadapter(this, r.layout.list_item, rowitems); listview.setadapter(adapter); listview.setonitemclicklistener(this); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { toast toast = toast.maketext(getapplicationcontext(), "item " + (position + 1) + ": " + rowitems.get(position), toast.length_short); toast.setgravity(gravity.bottom | gravity.center_horizontal, 0, 0); toast.show(); } }
rowitem
package com.theopentutorials.android.beans; public class rowitem { private int imageid; private string title; private string desc; public rowitem(int imageid, string title, string desc) { this.imageid = imageid; this.title = title; this.desc = desc; } public int getimageid() { return imageid; } public void setimageid(int imageid) { this.imageid = imageid; } public string getdesc() { return desc; } public void setdesc(string desc) { this.desc = desc; } public string gettitle() { return title; } public void settitle(string title) { this.title = title; } @override public string tostring() { return title + "\n" + desc; } } package com.theopentutorials.android.beans; import java.util.hashmap; import java.util.list; import com.theopentutorials.android.r; import android.content.context; import android.graphics.typeface; import android.view.view; import android.view.viewgroup; import android.widget.simpleadapter; import android.widget.textview; public class specialadapter extends simpleadapter { public specialadapter(context context, list<hashmap<string, string>> items, int resource, string[] from, int[] to) { super(context, items, resource, from, to); } public view getview(int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); ((textview) view.findviewbyid(r.id.desc)).settypeface(typeface .createfromasset(view.getcontext().getassets(), "fonts/iskpotab.ttf")); ((textview) view.findviewbyid(r.id.title)).settypeface(typeface .createfromasset(view.getcontext().getassets(), "fonts/iskpotab.ttf")); return view; } }
Comments
Post a Comment