回收器中的进度对话框查看适配器问题



当我尝试在回收器视图适配器中使用进度对话框时,我收到异常消息:

Unable to add window -- token null is not for an application

我知道使用上下文的所有内容都可以,因为滑动进度栏下方的几行使用相同的上下文。知道有什么问题吗?我的适配器类:

import android.app.ProgressDialog;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import java.util.List;

public class ShopsAdapter extends RecyclerView.Adapter<ShopsAdapter.MyViewHolder> {
    Context mContext;
    List<String> shopsList;
    ProgressDialog progressDialog;
    public class MyViewHolder extends RecyclerView.ViewHolder {
        public ImageView thumbnail;
        public MyViewHolder(View view) {
            super(view);
            thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
        }
    }
    public ShopsAdapter(Context mContext, List<String> shopsList) {
        this.mContext = mContext;
        this.shopsList = shopsList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.shop_card,parent,false);
        return new MyViewHolder(itemView);
    }
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        progressDialog = new ProgressDialog(mContext);
        shopsList.get(position);
        try{
            progressDialog.show();
            String stringformat = String.format(".../%s.png", shopsList.get(position));
            Glide.with(mContext).load(stringformat).listener(new RequestListener<String, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    return false;
                }
                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    //progressDialog.setVisibility(View.GONE);
                    return false;
                }
            }).centerCrop().fitCenter().into(holder.thumbnail);
        }catch (Exception e){
            Log.d("Dsdfs", e.getMessage());
            Glide.with(mContext).load("http://...Zabka.png").centerCrop().fitCenter().into(holder.thumbnail);
        }

    }
    @Override
    public int getItemCount() {
        return shopsList.size();
    }
}

更改

adapter = new ShopsAdapter(getApplicationContext((, shopsNames(;

适配器 = 新商店适配器(这个,商店名称(;

最新更新