Android自定义ListAdapter-更改字体
我的ListAdapter有问题 我是这样创建的:Android自定义ListAdapter-更改字体,android,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
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;
}
}
private ArrayAdapter<String> m_lapList;
setListAdapter(new ArrayAdapter<String>(this, R.layout.laps_row));
m_lapList = (ArrayAdapter<String>)getListAdapter();
如何使用我的新ListAdapter?要使用您提供的代码作为示例,它应该如下所示:
private MyAdapter m_lapList;
setListAdapter(new MyAdapter(this, new ArrayList<Object>()));
m_lapList = (MyAdapter)getListAdapter();
private MyAdapter m_lapList;
setListAdapter(新的MyAdapter(这个,新的ArrayList());
m_lapList=(MyAdapter)getListAdapter();
如何将其更改为私有MyAdapter m_lapList,这是一个字符串?作为提示,不要在getView()
中获取您的字体引用--它将在每次显示列表项时运行。在构造函数中获取引用(就像初始化上下文
和对象
变量一样),并在getView()中使用该引用。