How to use the data from the database in FireBase RecyclerAdapter?

I already looked some information about RecyclerAdapter, but unfortunately most of the sources of the English language and some aspects of I and the translator doesn't understand. So, here is my database
kPlyI.png

RecyclerAdapter classes in it:

public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View View = inflater.inflate(R. layout.coupon,parent,false);
return new ViewHolder(view);

OnBindViewHoder
public void onBindViewHolder(ViewHolder viewHolder, int position) {
 Coupons coupons = coupons2.get(position);
viewHolder.imageView.setImageResource(coupons.getLogo());
viewHolder.nameView.setText(coupons.getName());
viewHolder.sumView.setText(coupons.getSum());
}

getItemCount
public int getItemCount(){
 return coupons2.size();
}
 static class ViewHolder extends RecyclerView.ViewHolder{
 final ImageView imageView;
 final TextView nameView,sumView;
 ViewHolder(View v){
super(v);
 imageView = (ImageView) v.findViewById(R. id.logo);
 nameView = (TextView) v.findViewById(R. id.name);
 sumView = (TextView)v.findViewById(R. id.sum);
 }

All RecyclerAdapter.java:
class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
 private LayoutInflater inflater;
 private List<Coupons> coupons2;
 RecyclerAdapter(Context Context, List<Coupons> coupons2){
 this.coupons2 = coupons2;
 this.inflater = LayoutInflater.from(context);
}
@Override
 public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
 View View = inflater.inflate(R. layout.coupon,parent,false);
 return new ViewHolder(view);
}

@Override
 public void onBindViewHolder(ViewHolder viewHolder, int position) {
 Coupons coupons = coupons2.get(position);
viewHolder.imageView.setImageResource(coupons.getLogo());
viewHolder.nameView.setText(coupons.getName());
viewHolder.sumView.setText(coupons.getSum());
}

@Override
 public int getItemCount(){
 return coupons2.size();
}
 static class ViewHolder extends RecyclerView.ViewHolder{
 final ImageView imageView;
 final TextView nameView,sumView;
 ViewHolder(View v){
super(v);
 imageView = (ImageView) v.findViewById(R. id.logo);
 nameView = (TextView) v.findViewById(R. id.name);
 sumView = (TextView)v.findViewById(R. id.sum);
}
 }

LibraryActivity classes in it:

onCreate:
super.onCreate(savedInstanceState);
setContentView(R. layout.activity_library);
setInitialData();
 RecyclerView recyclerView = (RecyclerView) findViewById(R. id.list);
 RecyclerAdapter adapter = new RecyclerAdapter(this,couponss);
recyclerView.setAdapter(adapter);
 recyclerView.setLayoutManager(new LinearLayoutManager(this));
 DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
 Query Query = rootRef.child("Sirop");
 FirebaseRecyclerOptions<Coupons> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<Coupons>()
 .setQuery(query, Coupons.class)
 .build();


All LibraryActivity.java:
List<Coupons> couponss = new ArrayList<>();
@Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R. layout.activity_library);
setInitialData();
 RecyclerView recyclerView = (RecyclerView) findViewById(R. id.list);
 RecyclerAdapter adapter = new RecyclerAdapter(this,couponss);
recyclerView.setAdapter(adapter);
 recyclerView.setLayoutManager(new LinearLayoutManager(this));
 DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
 Query Query = rootRef.child("Sirop");
 FirebaseRecyclerOptions<Coupons> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<Coupons>()
 .setQuery(query, Coupons.class)
.build();

}
 private void setInitialData(){

 couponss.add(new Coupons("Feed","-500",R. drawable.aaaaaaaaaaa));
 }

All Coupons.java:
public class Coupons {
 private String name;
 private int logo;
 private String sum;

 public Coupons(String name, String sum, int logo) {
 this.name = name;
 this.sum = sum;
 this.logo = logo;
}
 public String getName() {
 return this.name;
}
 public void setName(String name) {
 this.name = name;
}
 public String getSum(){
 return this.sum;

}
 public void setSum(String sum){
 this.sum = sum;
}
 public int getLogo(){
 return this.logo;
}
 public void setLogo(int logo){
 this.logo = logo;
}
@Exclude
 public Map<String, Object> toMap() {
 HashMap<String, Object> result = new HashMap<>();
 result.put("name", name);
 result.put("sum", sum);
 result.put("logo", logo);
 return result;
 }

Where I erred?
March 20th 20 at 11:26
1 answer
March 20th 20 at 11:28
Solution
It is not enough just to update the data in the list. Still need to notify the adapter. In the method setInitialData. Pull method notifyDatasetChanged.

Find more questions by tags JavaAndroidFirebase