我想使用擴展BaseAdapter
的CustomAdapter創建ListView
。我有CustomAdapter(Context context, List<Map<String, String>> dataList)
。Android:使用CustomAdapter填充ListView
如何從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;
}
}
post CustomAdapter代碼 –
我編輯了我的問題。有我的來源。 – Martin
只是想確認你有地圖或位圖中的圖像路徑? –