我想ListView
使用扩展的 CustomAdapter创建BaseAdapter
。我有CustomAdapter(Context context, List<Map<String, String>> dataList)
。
如何从方法Map
中获取数据并设置我的视图getView()
?在我尝试使用之前,SimpleAdapter
但我需要设置存储在 SD 上的位图,以及我存储在地图中的图像的路径。感谢您的每一次帮助。
这是我的 CustomAdapter 的来源:
public class CustomAdapter extends BaseAdapter {
private Context context;
private String pricePrecision = null;
private List<Map<String, String>> data;
public CustomAdapter(Context context, List<Map<String, String>> data) {
super();
this.context = context;
this.data = data;
}
@Override
public int getCount() {
return (data == null) ? 0 : data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
LayoutInflater inflater = ((LayoutInflater) context
.getSystemService(Context.LOCATION_SERVICE));
if (convertView == null) {
convertView = inflater.inflate(R.layout.order_list_item, null);
viewHolder = new ViewHolder();
viewHolder.itemThumbnail = ((ImageView) convertView
.findViewById(R.id.ivItemThumb));
viewHolder.itemName = ((TextView) convertView
.findViewById(R.id.tvItemName));
viewHolder.itemPrice = ((TextView) convertView
.findViewById(R.id.tvItemPrice));
convertView.setTag(viewHolder);
} else {
viewHolder = ((ViewHolder) convertView.getTag());
}
return null;
}
private class ViewHolder {
private ImageView itemThumbnail;
private TextView itemName;
private TextView itemPrice;
}
}