gridview异步加载

迷途d书童 发布于 2012/03/26 18:47
阅读 447
收藏 0
 


package com.jh.dongyi.adapter;

import java.util.ArrayList;
import java.util.List;

import com.jh.dongyi.activity.CollborationActivity;
import com.jh.dongyi.activity.LocalePicDatailsActivity;
import com.jh.dongyi.activity.LocalePiccListActivity;
import com.jh.dongyi.activity.R;
import com.jh.dongyi.entity.InspectionInfo;
import com.jh.dongyi.entity.ProjectImage;
import com.jh.dongyi.util.DateParse;
import com.jh.dongyi.util.DownloadImageTask;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;
/**
 *
 * <code>ImageListAdapter</code>
 * @description: TODO(图片adapter)
 * @version  1.0
 * @author  liaoyp
 * @since 2011-12-12
 */
public class ImageListAdapter extends BaseAdapter {
 
 private LayoutInflater inflater;
 private List<ProjectImage> projectimageList;
 private Context context;
 private DownloadImageTask task;
 
 List<Bitmap> bitmapList  = new ArrayList<Bitmap>();
 private DownloadImageTask task2;
 
 public ImageListAdapter(Context context,
   List<ProjectImage>  projectimageList) {
  this.context = context;
  this.projectimageList = projectimageList;
  inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
  
 }

 public int getCount() {
  // TODO Auto-generated method stub
  return projectimageList.size();
 }

 public Object getItem(int position) {
  // TODO Auto-generated method stub
  return projectimageList.get(position);
 }

 public long getItemId(int position) {
  return position;
 }
 

 public View getView(final int position, View convertView, ViewGroup parent) {
  RelativeLayout gridview =null;
  if (convertView == null) {
   
   gridview = (RelativeLayout) inflater.inflate(R.layout.site_picture_imageview, null);

  } else {
   gridview = (RelativeLayout) convertView;
  }
  final ImageView imageView = (ImageView) gridview.findViewById(R.id.im_itemImage);
  final ProgressBar bar = (ProgressBar) gridview.findViewById(R.id.pb_bar);
  task2 = new DownloadImageTask(this,context, new ImageCallback(){
   // 回调函数,下载完图片直接更新gridview 显示
   public void imageLoaded(Bitmap imageBitmap) {
    bar.setVisibility(View.GONE);
    imageView.setImageBitmap(imageBitmap);
   }
   
  } );
  task2.execute(projectimageList.get(position).getThumbImage());

  imageView.setOnClickListener(new OnClickListener(){
   private Intent intent;

   public void onClick(View v) {
    intent = new Intent(context,LocalePicDatailsActivity.class);、、
    intent.putExtra("ProjectImage", projectimageList.get(position));
    context.startActivity(intent);
   }
   
  });
  
  return gridview;
 }
 
 

}


原文链接:http://blog.csdn.net/liao3841054/article/details/7093545
加载中
返回顶部
顶部