有没有办法将所有数据检索到 firebase Recycler Adapter,编辑它然后将其写入另一个数据库?

发布于 2025-01-18 10:06:26 字数 2837 浏览 0 评论 0原文

我正在开发出勤应用程序。基本上,我已经制作了所有所需信息的数据库,并且可以将其检索到Firebase适配器。但是,每当我尝试在出勤上设置值并将其发送到其他数据库时,都会显示一个数据。

唱片节目唯一的标记(没有约翰): “唱片秀唯一的标记(no

这是出席广播按钮

   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):
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文