Android自定义ListAdapter - 更改字体

时间:2012-09-27 14:37:39

标签: android

我的ListAdapter有问题。

我这样创建:

 public class MyAdapter extends BaseAdapter {

    private List<Object> objects;
    private final Context   context;

    public MyAdapter (Context context, List<Object> objects) {
        this.context = context;
        this.objects = objects;
    }


    public int getCount() {
        return objects.size();
    }

    public Object getItem(int position) {
        return objects.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

       Object obj = objects.get(position);

       tvRow = (TextView)findViewById(R.id.tvRow);
       tvRow.setText(obj.toString());

       Typeface typeface = Typeface.createFromAsset(getAssets(), "Fonts/DS-DIGIT.TTF");
           tvRow.setTypeface(typeface);
           return tvRow;
            }
    }

在使用我的自定义ListAdapter之前,我使用了它:

private ArrayAdapter<String> m_lapList;
setListAdapter(new ArrayAdapter<String>(this, R.layout.laps_row));
m_lapList = (ArrayAdapter<String>)getListAdapter();

如何使用我的新ListAdapter?

1 个答案:

答案 0 :(得分:0)

要使用您提供的代码作为示例,它应如下所示:

private MyAdapter m_lapList;
setListAdapter(new MyAdapter(this, new ArrayList<Object>()));
m_lapList = (MyAdapter)getListAdapter();