我正在编写一个简单的程序,存储每天喝的配方奶量。
private final String date = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());
FirebaseAuth fAuth = FirebaseAuth.getInstance();
private DatabaseReference feedRecordsDatabase = FirebaseDatabase.getInstance().getReference().child(fAuth.getCurrentUser().getUid()).child("feedRecords").child(date);
如您所见,每次我保存一条记录时,它将把日期保存为Feed记录的子项
令人讨厌的是,我今天只做了一个,所以为什么只有一个约会
我想打印出出现在RecyclerView中的每个日期
(之后,我将使它们可单击以进入并查看记录)
databaseReference = FirebaseDatabase.getInstance().getReference().child(fAuth.getCurrentUser().getUid()).child("feedRecords");
options = new FirebaseRecyclerOptions.Builder<Records>().setQuery(databaseReference,Records.class).build();
adapter = new FirebaseRecyclerAdapter<Records, RecordsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull RecordsViewHolder holder, int position, @NonNull Records model) {
}
@NonNull
@Override
public RecordsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.saved_records_view,viewGroup,false);
return new RecordsViewHolder(view);
}
};
GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),1);
recyclerView.setLayoutManager(gridLayoutManager);
adapter.startListening();
recyclerView.setAdapter(adapter);
}
我正在努力寻找一种将所有提要记录的子项打印到我的recyclerView中的方法,我相信我需要的代码是进入onBindViewHolder
例如,我希望recyclerview目前仅填充04-02-2019,但是如果我要在接下来的几天添加更多记录,那么这几天也将填充
我正在努力引用这个孩子,因为它每天都会变化
我们非常感谢您的帮助,如果我没有清楚地说明原因,请告诉我,以便澄清
Records.java
package com.example.lewisthompson.childcareapplication;
public class Records {
public String timestamp;
public Records(){
}
public Records(String timestamp) {
this.timestamp = timestamp;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
}
RecordsViewHolder.java
package com.example.lewisthompson.childcareapplication;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
public class RecordsViewHolder extends RecyclerView.ViewHolder {
TextView t1;
public RecordsViewHolder(@NonNull View itemView) {
super(itemView);
t1 = itemView.findViewById(R.id.record_date);
}
}