0

I'm using Firebase as a database and a preview to get information about the saved data, now I can bring both the image and the name of that image in my view, but now I would like to be able to click on the quick view and open a new fragment or activity where the same image or publication can be displayed that is clicked, that is, the photo, the name and the power to include other data within that new fragment or activity when clicking on the recyclerview post.

In a few words for example: a clothing store, you have a recycling view with your products and your name, click on that product opens but with all the other details and specifications you have.

I am currently using: Firebase navigation button with fragments

Fragment where the recyclerview is shown:

mRecyclerView = v.findViewById(R.id.recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    mUploads = new ArrayList<>();

    mDatabaseRef = FirebaseDatabase.getInstance().getReference("Posts");

    mDatabaseRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                Uploads uploads = postSnapshot.getValue(Uploads.class);
                mUploads.add(uploads);
            }

            mAdapter = new ImageAdapter(getActivity(), mUploads);

            mRecyclerView.setAdapter(mAdapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });return v;

//adapter code

public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private Context mContext;
private List<Uploads> mUploads;


public ImageAdapter(Context context, List<Uploads> uploads) {
    mContext = context;
    mUploads = uploads;
}

@Override
public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(mContext).inflate(R.layout.home_item, parent, false);
    return new ImageViewHolder(v);
}



@Override
public void onBindViewHolder(ImageViewHolder holder, final int position) {
    Uploads uploadCurrent = mUploads.get(position);
    holder.textViewName.setText(uploadCurrent.getName());
    Picasso.get()
            .load(uploadCurrent.getImageUrl())
            .placeholder(R.mipmap.ic_launcher)
            .into(holder.imageView);

}

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

public class ImageViewHolder extends RecyclerView.ViewHolder {
    public TextView textViewName;
    public ImageView imageView;


    public ImageViewHolder(View itemView) {
        super(itemView);

        textViewName = itemView.findViewById(R.id.Descripcion);
        imageView = itemView.findViewById(R.id.ImagePro);
    }
}

}

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Ibrahim
  • 23
  • 8

1 Answers1

0

You have two options.

  1. You can create a callback interface and trigger the callback method from your Adapter's onClick. The activity or fragment that implemented the interface and passed the instance of it to the Adapter will get the callback and you can launch a quick view from there. I prefer this method. Here you can find a detailed example to achieve this.

  2. Since you already have Context in your class, you can directly reference a method in an Activity or Fragment and create a quick view Fragment from there.

    public void onBindViewHolder(ImageViewHolder holder, final int position) {
         ((YourActivity) context).startQuickviewFragment();
    }
    
WasabiTea
  • 389
  • 2
  • 10