0

我的 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;
            }
    }

在使用我的 custom 之前ListAdapter,我是这样使用它的:

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

如何使用我的新 ListAdapter?

4

1 回答 1

0

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

private MyAdapter m_lapList;
setListAdapter(new MyAdapter(this, new ArrayList<Object>()));
m_lapList = (MyAdapter)getListAdapter();
于 2012-09-27T14:45:42.760 回答