我想在下载时在我的自定义适配器中显示progressBar!
有我的适配器类
public class ImageAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = ((Activity) context).getLayoutInflater().inflate(layoutResourceId, parent, false);
holder.pictureView = (GalerieImageView) convertView.findViewById(R.id.GalerieView);
holder.progressBar = (ProgressBar) convertView.findViewById(R.id.progressBarGalerie);
holder.progressBar.setVisibility(View.VISIBLE);
holder.progressBar.setIndeterminate(true);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ImageLoader imageLoader = ImageCacheManager.getInstance().getImageLoader();
if (arrayList.get(position).getTurl() != null) {
Log.i("lien", "" + arrayList.get(position).getTurl());
holder.pictureView.setImageUrl(arrayList.get(position).getTurl(), imageLoader);
holder.pictureView.setVisibility(View.VISIBLE);
holder.pictureView.setDefaultImageResId(R.drawable.ico_loading);
holder.pictureView.setErrorImageResId(R.drawable.ico_error);
holder.pictureView.setLayoutParams(new RelativeLayout.LayoutParams(imageWidth, imageWidth));
holder.pictureView
.setResponseObserver(new GalerieImageView.ResponseObserver() {
@Override
public void onError() {
holder.progressBar.setVisibility(View.GONE);
}
@Override
public void onSuccess() {
holder.progressBar.setVisibility(View.GONE);
}
});
} else {
//holder.pictureView.setVisibility(View.GONE);
}
return convertView;
}
}
我的自定义Networkview with Observer(GaleryImageView)它基于this StackOverFlow answer。我无法显示进度条。
答案 0 :(得分:2)
我正是这样做的。我将进度条包装在调用Activity / Fragment的方法中,而不是适配器本身。类似的东西:
public void startProgressBar() {
dialog = new ProgressDialog(this);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.setMessage("MEssgae");
dialog.show();
}
Dialog是班级成员。
现在当我打电话时,我的下一个电话是startProgressBar - 我取消了onResese和onError对话框。
所以它变成了
doVolleyCommand(URL);
startProgressBar();
在我的回复处理程序中:
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}