0

我有如下代码:

SpecialAdapter adapter = new SpecialAdapter(
                                this, 
                                list, 
                                R.layout.list_display_item, 
                                from, 
                                to );

        myTextListView.setAdapter(adapter); 

.
.
.
.

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);
        }

        @Override

        public View getView(
int position, View convertView, ViewGroup parent)
 {
          View view = super.getView(position, convertView, parent);
                }
    }

list_display_item.xml

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/myDisplayItemLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:orientation="vertical">

        <TextView
            android:id="@+id/arabicTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right|center_vertical"
            android:lineSpacingMultiplier="3"
            android:text="Arabic"
            android:textSize="30dp"/>

        <TextView
            android:id="@+id/translationTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="English" 
            android:gravity="left|center_vertical"
            android:textSize="30dp"/>

    </LinearLayout> 

我只想将我自己的阿拉伯字体设置为 android:id="@+id/arabicTextView" 并将英文字体设置为 android:id="@+id/translationTextView"。

在 SpecialAdapter 类的 getView() 函数中,我得到 View view = super.getView(position, convertView, parent) 和 view.getId() 实际上是 linearlayout android:id="@+id/myDisplayItemLinearLayout" 的 id

我只是想获得这个linearLayout的内部textviews来为每个使用字体设置单独的字体......我怎样才能在那里获得这些textViews?

在这里设置我的字体是正确的方法还是应该以其他方式完成???请帮我..

4

1 回答 1

3

使用findViewById方法ViewsetTypeface方法TextView

public View getView(int position, View convertView, ViewGroup parent)
{
    View view = super.getView(position, convertView, parent);

    //assuming you've put your arabic font file in your assets directory
    ((TextView)view.findViewById(R.id.arabicTextView)).setTypeface(Typeface.createFromAsset(view.getContext().getAssets(), "yourarabicfont.otf"));

    //assuming you've put some custom english font in your assets directory
    ((TextView)view.findViewById(R.id.translationTextView)).setTypeface(Typeface.createFromAsset(view.getContext().getAssets(), "yourenglishfont.otf"));

    return view;
}
于 2012-02-10T14:53:01.980 回答