SimpleCursadapter を使用するアプリケーションを作成しました。
String[] from = new String[] {"title","notes","image"};
int[] to = new int[] { R.id.esodaTextView, R.id.amountTextView, R.id.imageView1};
esodaAdapter = new SimpleCursorAdapter (this, R.layout.recipe_list_item, null, from, to);
ご覧のとおり、2 つの TextView (esodaTextView + amountTextView) と 1 つの imageView で 3 つのデータを表示しています。
問題は、これらの 2 つの TextViews (esodaTextView + amountTextView) にカスタム フォント (assets フォルダーに保存されている) を設定して、カスタム フォントでテキストを表示する方法です。
これは、リスト アイテムの xml ファイルです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:background="#55eee9e9" >
<TextView
android:id="@+id/esodaTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20dp"
android:textColor="#000000"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" />
<TextView
android:id="@+id/amountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/esodaTextView"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingBottom="5dp"
android:textSize="12dp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
次のコードを使用してカスタム フォントをプログラムで設定できることはわかっていますが、Simplecursodaptor 内で使用するにはどうすればよいですか?
TextView txt1 = (TextView) findViewById(R.id.textView1);
Typeface font = Typeface.createFromAsset(getAssets(), "segoescb.ttf");
txt1.setTypeface(font);
よろしくお願いいたします。