我已经有了从url加载的图像的列表视图。 我想在加载时在每个图像中添加类似旋转圆圈的内容。 现在,我使用我的默认值来替换正在加载的图像。 我最主要发现的是,让所有的类都扩展AsyncTask。那么,我有这个:在图像加载时添加加载的圆形动画
我有一个活动,解析json完成。 然后我有一个MyCustomAdapter延伸BaseAdapter:
//constructor
public MyCustomAdapter (Context c, List<RowItem> items){
this.context = c;
this.sRowItems = items;
imageLoader=new ImageLoader(c.getApplicationContext());
}
.
.
.
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if(convertView == null){
convertView = inflater.inflate(R.layout.list_layout, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.name);
holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
holder.imageView = (ImageView) convertView.findViewById(R.id.prof_pic);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
RowItem sItem = (RowItem) getItem(position);
holder.txtName.setText(sItem.getShopName());
holder.txtDesc.setText(sItem.getShopDesc());
imageLoader.DisplayImage(sItem.getImageUrl(), holder.imageView);
return convertView;
}
然后,我有我的图像加载类。所以,而不是AsyncTask,我使用普通的Java线程。它 一部分是这样的:
public class ImageLoader {
MemoryCache memoryCache=new MemoryCache();
FileCache fileCache;
private Map<ImageView, String> imageViews=Collections.synchronizedMap(new WeakHashMap<ImageView, String>());
ExecutorService executorService;
public ImageLoader(Context context){
fileCache=new FileCache(context);
executorService=Executors.newFixedThreadPool(5);
}
final int stub_id=R.drawable.ic_launcher;
public void DisplayImage(String url, ImageView imageView)
{
imageViews.put(imageView, url);
Bitmap bitmap=memoryCache.get(url);
if(bitmap!=null)
imageView.setImageBitmap(bitmap);
else
{
queuePhoto(url, imageView);
imageView.setImageResource(stub_id);
}
}
private void queuePhoto(String url, ImageView imageView)
{
PhotoToLoad p=new PhotoToLoad(url, imageView);
executorService.submit(new PhotosLoader(p));
}
我看到这里的答案在计算器使用
ProgressDialog mDialog = new ProgressDialog(getApplicationContext());
但是,当我把它放在我的ImageLoader的类就没有我的代码工作。 我很难实现这个加载动画圈。 请任何帮助。非常感谢。
好的,我会给这个我拍.. – elL 2013-03-19 06:18:37