试着这样做,希望这能帮助你解决问题。
public class ImageAdapter extends BaseAdapter {
private Context context;
private ArrayList<HashMap<String,String>> list;
private Animation anim;
public ImageAdapter(Context context, ArrayList<String> imageList){
this.context = context;
list = new ArrayList<HashMap<String, String>>();
for (String image : imageList){
HashMap<String,String> row = new HashMap<String, String>();
row.put("image",image);
row.put("count","0");
list.add(row);
}
anim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
}
@Override
public int getCount(){
return list.size();
}
@Override
public Object getItem(int position){
return list.get(position);
}
@Override
public long getItemId(int position){
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
holder =new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.row_multiphoto_item, null);
holder.imageView = (ImageView)convertView.findViewById(R.id.imageView1);
holder.click_count = (TextView)convertView.findViewById(R.id.count);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.imageView.setAnimation(anim);
imageLoader.displayImage("file://"+list.get(position).get("image").toString(), holder.imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(Bitmap loadedImage) {
anim.start();
}
});
holder.click_count.setText(String.valueOf(list.get(position).get("count")));
if(list.get(position).get("count").equals("0")){
holder.click_count.setVisibility(View.INVISIBLE);
}else{
holder.click_count.setVisibility(View.VISIBLE);
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
list.get(position).put("count",String.valueOf(Integer.parseInt(list.get(position).get("count"))+1));
notifyDataSetChanged();
}
});
return convertView;
}
class ViewHolder{
ImageView imageView;
TextView click_count;
}
}