У меня есть этот фрагмент:
public class AttractionsFragment extends Fragment {
Context context;
private View LocationView;
private RecyclerView myLocationsRecycler;
private DatabaseReference ModelRef;
public AttractionsFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
LocationView = inflater.inflate(R.layout.fragment_blank, container, false);
myLocationsRecycler = LocationView.findViewById(R.id.cat_recycler);
myLocationsRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
FirebaseApp.initializeApp(context);
ModelRef = FirebaseDatabase.getInstance().getReference().child("attraction_list");
return LocationView;
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerOptions<Model> options = new FirebaseRecyclerOptions.Builder<Model>()
.setQuery(ModelRef, Model.class)
.build();
FirebaseRecyclerAdapter<Model, ModelViewHolder> adapter = new FirebaseRecyclerAdapter<Model, ModelViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final ModelViewHolder holder, int position, @NonNull Model model) {
ModelRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot data: dataSnapshot.getChildren()){
String name = data.child("name").getValue().toString();
String image=data.child("image_link").getValue().toString();
holder.title.setText(name);
Picasso.get().load(image).into(holder.imageBg);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@NonNull
@Override
public ModelViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_item_layout, viewGroup, false);
return new ModelViewHolder(view);
}
};
myLocationsRecycler.setAdapter(adapter);
adapter.startListening();
}
public static class ModelViewHolder extends RecyclerView.ViewHolder {
ImageView imageBg;
TextView title;
public ModelViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
imageBg = itemView.findViewById(R.id.image);
}
}
}
И эта база данных
{
"attraction_list": {
"01":{
"name": "Eye of London",
"image_link": "gs://for-tourists-by-tourists.appspot.com/images/eye_london.png",
"full_description": "As iconic for London as the Eiffel Tower is to Paris, the Coca-Cola London Eye is a spectacular testament to modern Britain. At 135 metres, the London Eye is one of the world's tallest observation wheels, providing up to 40 kilometres of panoramic views on a clear day. The gradual rotation in one of the 32 high-tech glass capsules takes approximately 30 minutes, offering breathtaking views of London and its famous landmarks. Whether it’s with family, friends or maybe a romantic Champagne Experience just for two, London Eye tickets are an integral part of any trip to London. See more of London for less with 365Tickets exclusive London Eye combination tickets."
},
"02":{
"name": "Tower Bridge",
"image_link": "gs://for-tourists-by-tourists.appspot.com/images/tower_bridge.png",
"full_description": "Completed in 1894 The Most Famous Bridge in the World is a marvel of Victorian engineering and the home of the Tower Bridge Exhibition. At 42 metres above the river Thames, a visit to the Tower Bridge exhibition boasts spectacular panoramic views of some of London’s most famous landmarks: The London Eye, Canary Wharf, and St Paul’s Cathedral can all be seen from its high-level walkways – and the budding photographers will love that the specially designed windows make capturing that iconic image an easy task. Visitors to the exhibition will discover the rich history of Tower Bridge with an ever changing variety of content throughout the year."
},
"03":{
"name": "Buckingham Palace",
"image_link": "gs://for-tourists-by-tourists.appspot.com/images/buckingham.png",
"full_description": "Since 1837, Buckingham Palace has served as the official London residence of Britain's kings and queens. Today, we know it as the administrative headquarters of Her Majesty, Queen Elizabeth II."
},
"04":{
"
имя ":" Биг Бен ",
"image_link": "gs: //for-tourists-by-tourists.appspot.com/images/big_ben.png",
"full_description": "Несмотря на то, что во время летнего перерыва взимается плата за туры в здание Парламента (Вестминстерский дворец), которые доступны для всех, жители Великобритании могут совершить экскурсию ..."
}
}
И в моем приложении все мои карты обновляются с заголовком «Биг Бен» и этим изображением, помогите мне добавить в каждую карту отдельный элемент.
Странно то, что у меня есть только 4 карты (как я должен)