Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android自定义ListAdapter-更改字体_Android - Fatal编程技术网

Android自定义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

我的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;
            }
    }
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()中使用该引用。