Not able to print all childs from my firebase database

你。 提交于 2020-07-16 08:00:07

问题


Output of all the datessnippet of my firebase database

I want to print all dates(childs) details from 5th of july to 7th of july from my database but i only get top date(child)[7th july] as my output instead of all of the child nodes**

Here is my reference where i get values from database and put into RecyclerView adapter

DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Dateinfo").child(firebaseUser.getUid());
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                mdates.clear();
                    for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                        Dateinfo dateinfo = snapshot.getValue(Dateinfo.class);
                        mdates.add(dateinfo);
                    }
                    Collections.reverse(mdates);
                    dateAdapter.notifyDataSetChanged();
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
    }

And here is my Adapter

public class DateAdapter extends RecyclerView.Adapter<DateAdapter.ViewHolder> {
private Context mContext;
private List<Dateinfo> mdates;
FirebaseUser firebaseUser;

public DateAdapter(Context mContext, List<Dateinfo> mdates) {
    this.mContext = mContext;
    this.mdates = mdates;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.date_item,parent,false);
    return new DateAdapter.ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    firebaseUser= FirebaseAuth.getInstance().getCurrentUser();
    final Dateinfo dateinfo =mdates.get(position);
    holder.date.setText(dateinfo.getDate());
    holder.steps.setText(String.valueOf(dateinfo.getSteps()));
    String timeformat = String.format(Locale.getDefault(),"%.2f", dateinfo.getDistance());
    holder.distance.setText(timeformat);
}

@Override
public int getItemCount() {
    return Math.min(mdates.size(),10);
}

public class ViewHolder extends RecyclerView.ViewHolder{
    public TextView date;
    public TextView steps,distance;
    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        date=itemView.findViewById(R.id.dateview);
        steps=itemView.findViewById(R.id.steps);
        distance=itemView.findViewById(R.id.distance);
    }
}

This is my Dateinfo class:

public class Dateinfo {
    long steps;
    String ID;
    String date;
    double distance;

    public Dateinfo() {
    }

    public Dateinfo(long steps, String ID, String date, double distance) {
        this.steps = steps;
        this.ID=ID;
        this.date=date;
        this.distance=distance;

    }
    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public long getSteps() {
        return steps;
    }

    public void setSteps(long steps) {
        this.steps = steps;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }



    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }
}

来源:https://stackoverflow.com/questions/62765412/not-able-to-print-all-childs-from-my-firebase-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!