You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null

前端 未结 5 1193
别跟我提以往
别跟我提以往 2021-01-13 21:26

I am using FragmentStatePagerAdapter to show around 5 fragments in an activity.On each activity I am showing the images which I am fetching from FirebaseListAdapter/Firebase

5条回答
  •  遥遥无期
    2021-01-13 21:50

    I Found this way too

    public class NoteAdapter extends FirestoreRecyclerAdapter {
    
    Context context;
    
    public NoteAdapter(@NonNull FirestoreRecyclerOptions options) {
        super(options);
    }
    
    @Override
    protected void onBindViewHolder(@NonNull NoteHolder holder, int position, @NonNull final Note model) {
    
    
        context = holder.itemView.getContext();
    
        holder.r_tv.setText(model.getTitle());
        Glide.with(context).load(model.getImage()).into(holder.r_iv);
    
    
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, CategoryProductActivity.class);
                MainActivity.myCategory2 = model.getTitle();
                MainActivity.myCategoryIcon2 = model.getImage();
                context.startActivity(i);
            }
        });
    
    }
    
    @NonNull
    @Override
    public NoteHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_category,parent,false);
    
        return new NoteHolder(v);
    }
    
    public static class NoteHolder extends RecyclerView.ViewHolder
    {
        TextView r_tv;
        ImageView r_iv;
    
        public NoteHolder(@NonNull View itemView) {
            super(itemView);
    
            r_tv = itemView.findViewById(R.id.r_tv);
            r_iv = itemView.findViewById(R.id.r_iv);
    
    
        }
    }
    }
    

提交回复
热议问题