android - Change font in my listView -
so listview of mine giving me headaches. working , all, can't seem change font of text in lv.
this code:
public class myactivity3 extends activity { private textview tv; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my3); button m = (button) findviewbyid(r.id.button3); tv = (textview) findviewbyid(r.id.textviewcat); typeface typeface = typeface.createfromasset(getassets(), "bebasneue bold.ttf"); tv.settypeface(typeface); string listarray[] = new string[] { "india", "england", "canada", "new zealand", "south africa", "pakistan", "west indies" }; int icon[] = new int[] { r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher }; listview listview = (listview) findviewbyid(r.id.listview); list<hashmap<string, string>> alist = new arraylist<hashmap<string, string>>(); (int = 0; <= listarray.length - 1; i++) { hashmap<string, string> hm = new hashmap<string, string>(); hm.put("title", listarray[i]); hm.put("icon", integer.tostring(icon[i])); alist.add(hm); } string[] sfrm = { "title", "icon" }; int[] sto = { r.id.title, r.id.list_image}; simpleadapter adapter = new simpleadapter(getbasecontext(), alist, r.layout.row_layout, sfrm, sto); listview.setadapter(adapter); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view view, int position, long id) { switch (position) { case 0: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; case 1: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; case 2: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; case 3: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; case 4: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; case 5: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; case 6: toast.maketext(getapplicationcontext(), "", toast.length_short).show(); break; } } }); } @override public void onbackpressed() { super.onbackpressed(); overridependingtransition(r.anim.animation8, r.anim.animation7); } }
row_layout.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="5dip" > <linearlayout android:id="@+id/thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_marginright="5dip" android:padding="3dip" > <imageview android:id="@+id/list_image" android:layout_width="50dip" android:layout_height="50dip" android:src="@drawable/ic_launcher" /> </linearlayout> <textview android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centervertical="true" android:layout_torightof="@+id/thumbnail" android:text="country name" android:textcolor="#ffffff" android:textsize="30sp" android:typeface="sans" /> </relativelayout>
so code, can see there textview id "title". how can change font of title? i'd apreciate if answer question based on code, because tried other solutions on no succes
here detailed explanation of issue.
http://javatechig.com/android/using-external-fonts-in-android-view
basically you, since it's in listview recommend create custom textview. it's important place font files in assets folder.
saying tried other sources no success wrong, above link appears second google search result , works perfectly.
Comments
Post a Comment