public class AroundAdapter extends BaseAdapter {
private ArrayList<MaintanceShopItem> aroundList;
private LayoutInflater inflater;
private ImageFetcher imageFetcher;
public AroundAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
public AroundAdapter(Context context, ArrayList<MaintanceShopItem> urgents) {
this.aroundList = urgents;
inflater = LayoutInflater.from(context);
notifyDataSetInvalidated();
}
public AroundAdapter(Context context, ArrayList<MaintanceShopItem> urgents,
ImageFetcher imageFetcher) {
this.aroundList = urgents;
inflater = LayoutInflater.from(context);
this.imageFetcher = imageFetcher;
notifyDataSetInvalidated();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return aroundList == null ? 0 : aroundList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return aroundList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.around_list_item, null);
viewHolder = new ViewHolder();
viewHolder.around_imageview = (ImageView) convertView.findViewById(R.id.around_imageView1);
viewHolder.around_complany_name = (TextView) convertView.findViewById(R.id.around_complany_name);
viewHolder.around_complany_address = (TextView) convertView.findViewById(R.id.around_complany_address);
viewHolder.around_complany_distance = (TextView) convertView
.findViewById(R.id.around_complany_distance);
viewHolder.around_complany_star = (RatingBar) convertView.findViewById(R.id.around_complany_start);
viewHolder.around_complany_scope = (TextView) convertView.findViewById(R.id.around_complany_scope);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
MaintanceShopItem item = aroundList.get(position);
viewHolder.around_complany_name.setText(item.getStoreBasic().getStoreName());
viewHolder.around_complany_address.setText(item.getStoreBasic().getStoreAddress());
String kilomiter = String.valueOf(Integer.parseInt(item.getStoreBasic().getStoreDistance()) / 10 / 100.0)
+ "Km";
viewHolder.around_complany_distance.setText(kilomiter);
viewHolder.around_complany_star.setStepSize(0.5f);
viewHolder.around_complany_star.setRating(Float.valueOf(item.getStoreBasic().getStoreStar()));
viewHolder.around_complany_scope.setText(item.getStoreBasic().getStoreScope());
//dealing with the image url
viewHolder.around_imageview.setTag(item.getStoreBasic().getStoreImage());// ���ñ�ǩ
Log.v("imageUrl", item.getStoreBasic().getStoreImage());
if (imageFetcher != null)
imageFetcher.loadImage(item.getStoreBasic().getStoreImage(), viewHolder.around_imageview);
return convertView;
}
static class ViewHolder {
private ImageView around_imageview;
private TextView around_complany_name;
private TextView around_complany_address;
private TextView around_complany_distance;
private RatingBar around_complany_star;
private TextView around_complany_scope;
}
}