// Initialize Firebase databaseReference = FirebaseDatabase.getInstance().getReference().child("Item2").child(parentId); // Initialize RecyclerView recyclerView = findViewById(R.id.recyclerViewSecond); recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); // Set up FirebaseRecyclerAdapter FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder() .setQuery(databaseReference, Item2.class) .build(); FirebaseRecyclerAdapter adapter = new eRecyclerAdapter(options) { @Override protected void onBindViewHolder(@NonNull Item2ViewHolder holder, int position, @NonNull Item2 model) { holder.setTitle(model.title); holder.setImage(model.imageURL); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Handle item click, start ThirdActivity Intent intent = new Intent(SecondActivity.this, ThirdActivity.class); intent.putExtra("parentId", model.parentId); startActivity(intent); } }); } @NonNull @Override public Item2ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item2_layout, parent, false); return new Item2ViewHolder(view); } }; recyclerView.setAdapter(adapter); adapter.startListening(); } // ViewHolder for Item2 public static class Item2ViewHolder extends RecyclerView.ViewHolder { public Item2ViewHolder(@NonNull View itemView) { super(itemView); } public void setTitle(String title) { // Set title in your UI } public void setImage(String imageURL) { // Load image into ImageView using a library like Glide or Picasso } }
library like Glide or Picasso } }