我在解析 web 服务响应后获得了一个列表。我已经使用BaseAdapter
. 我面临的问题是我无法ListView
使用我创建的自定义视图将数据绑定到。这是我的自定义视图:
public class ItemListBaseAdapter extends BaseAdapter {
int layoutResourceId;
private static List<Item> itemDetailsarrayList;
private LayoutInflater l_Inflater;
public ItemListBaseAdapter(Context context, List<Item> results) {
itemDetailsarrayList = results;
l_Inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.row_layout, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtTitle.setText(itemDetailsarrayList.get(position).getCity_name());
return convertView;
}
static class ViewHolder {
TextView txtTitle;
}
}
这就是我试图绑定的方式:
llstCities = Objparsecities.parse();
ItemListBaseAdapter adapter = new ItemListBaseAdapter(this, lstCities);
lstcities = (ListView)findViewById(R.id.listView1);
lstcities.setAdapter(adapter);