tags:

views:

59

answers:

1
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Typeface font = Typeface.createFromAsset(
                getAssets(), "DejaVuSans.ttf");

        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
                        getGroups()));

        tv = (TextView)findViewById(R.id.textitem);

        //Uncomment a line below and the app crashes!!
        //tv.setTypeface(font);
        //tv.setGravity(Gravity.LEFT);

}

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textitem"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp"
    android:gravity="right"
/>

The problem is that I want to set a new typeface for the TextView in the ListView, and it seems it can't be done in the XML file!!

A: 

You can create the custom Adapter and can set the font face in that adapter. Here is one workable solution.

zawhtut