我有自己的类数组列表,我需要绑定该列表并仅向用户显示一些字段。我已经通过扩展 BaseAdapter 类来创建自己的适配器类来尝试这一点。但我只显示了一个字段(名字),我需要显示更多。这是我的适配器类,
private class MyGriAdapter extends BaseAdapter{
ArrayList<Doctor> data;
public MyGriAdapter(ArrayList<Doctor> data){
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView vv = new TextView(getApplicationContext());
vv.setTextColor(Color.BLACK);
vv.setText(data.get(position).firstname);
return vv;
}
@Override
public Object getItem(int arg0) {
return data.get(arg0);
}
@Override
public long getItemId(int position) {
return position;
}
}
我的按钮单击事件我正在绑定数据(doctorResultList 是 Doctor 类型的数组列表),
GridView grid_main = (GridView)findViewById(R.id.GridView01);
MyGriAdapter grdAdapter = new MyGriAdapter(doctorResultList);
grid_main.setAdapter(grdAdapter);