有没有办法将所有数据检索到 firebase Recycler Adapter,编辑它然后将其写入另一个数据库?
我正在开发出勤应用程序。基本上,我已经制作了所有所需信息的数据库,并且可以将其检索到Firebase适配器。但是,每当我尝试在出勤上设置值并将其发送到其他数据库时,都会显示一个数据。
唱片节目唯一的标记(没有约翰):
optionAttendanceData = new FirebaseRecyclerOptions.Builder<AttendanceCustom>()
.setQuery(mQueryAttendanceData, AttendanceCustom.class).build();
firebaseRecyclerAdapterAttendanceData = new FirebaseRecyclerAdapter<AttendanceCustom, AttendanceDataCustomViewHolder>(optionAttendanceData) {
@Override
protected void onBindViewHolder(@NonNull AttendanceDataCustomViewHolder holder, int position, @NonNull AttendanceCustom model) {
holder.setDetails(model.getFirstName(), model.getLastName());
firstName = model.getFirstName();
lastName = model.getLastName();
attendance = model.getAttendance();
description = model.getDesctiption();
date = model.getDate();
}
@NonNull
@Override
public AttendanceDataCustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
mViewAttendanceData = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_attendance_data, parent, false);
return new AttendanceDataCustomViewHolder(mViewAttendanceData);
}
};
mRecyclerViewAttendanceData.setAdapter(firebaseRecyclerAdapterAttendanceData);
firebaseRecyclerAdapterAttendanceData.startListening();
firebaseRecyclerAdapterAttendanceData.notifyDataSetChanged();
}
public class AttendanceDataCustomViewHolder extends RecyclerView.ViewHolder {
public AttendanceDataCustomViewHolder(View itemView) {
super(itemView);
mViewAttendanceData = itemView;
}
private void setDetails(String first, String last) {
TextView tv_first = mViewAttendanceData.findViewById(R.id.tv_attendance_data_first_name);
TextView tv_last = mViewAttendanceData.findViewById(R.id.tv_attendance_data_last_name);
tv_first.setText(first);
tv_last.setText(last);
radioButtonAttendance();
}
public void sendData(){
randomNumber = random.nextInt(10000);
DatabaseReference dataRefAttendance = FirebaseDatabase.getInstance().getReference("Attendance").child("Record");
AttendanceCustom attendanceCustom = new AttendanceCustom(firstName, lastName, date, description, attendance, numberDate);
newKey = dataRefAttendance.child("Attendance").child("record").push().getKey();
dataRefAttendance.child(firstName + "-" + lastName + "-" + randomNumber).setValue(attendanceCustom);
}
I am working on an attendance app. Basically, I have already made the database of all the info needed and I can retrieve it to the firebase adapter. However, every time I tried to set the value on the attendance and send it to the other database it will only show one data.
Record show's only Mark (no John):
This is the attendance radio button
optionAttendanceData = new FirebaseRecyclerOptions.Builder<AttendanceCustom>()
.setQuery(mQueryAttendanceData, AttendanceCustom.class).build();
firebaseRecyclerAdapterAttendanceData = new FirebaseRecyclerAdapter<AttendanceCustom, AttendanceDataCustomViewHolder>(optionAttendanceData) {
@Override
protected void onBindViewHolder(@NonNull AttendanceDataCustomViewHolder holder, int position, @NonNull AttendanceCustom model) {
holder.setDetails(model.getFirstName(), model.getLastName());
firstName = model.getFirstName();
lastName = model.getLastName();
attendance = model.getAttendance();
description = model.getDesctiption();
date = model.getDate();
}
@NonNull
@Override
public AttendanceDataCustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
mViewAttendanceData = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_attendance_data, parent, false);
return new AttendanceDataCustomViewHolder(mViewAttendanceData);
}
};
mRecyclerViewAttendanceData.setAdapter(firebaseRecyclerAdapterAttendanceData);
firebaseRecyclerAdapterAttendanceData.startListening();
firebaseRecyclerAdapterAttendanceData.notifyDataSetChanged();
}
public class AttendanceDataCustomViewHolder extends RecyclerView.ViewHolder {
public AttendanceDataCustomViewHolder(View itemView) {
super(itemView);
mViewAttendanceData = itemView;
}
private void setDetails(String first, String last) {
TextView tv_first = mViewAttendanceData.findViewById(R.id.tv_attendance_data_first_name);
TextView tv_last = mViewAttendanceData.findViewById(R.id.tv_attendance_data_last_name);
tv_first.setText(first);
tv_last.setText(last);
radioButtonAttendance();
}
public void sendData(){
randomNumber = random.nextInt(10000);
DatabaseReference dataRefAttendance = FirebaseDatabase.getInstance().getReference("Attendance").child("Record");
AttendanceCustom attendanceCustom = new AttendanceCustom(firstName, lastName, date, description, attendance, numberDate);
newKey = dataRefAttendance.child("Attendance").child("record").push().getKey();
dataRefAttendance.child(firstName + "-" + lastName + "-" + randomNumber).setValue(attendanceCustom);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论