通过自定义适配器更新子值

时间:2019-04-23 10:22:53

标签: android firebase firebase-realtime-database

我想使用自定义适配器更新Firebase数据库中的值,我在调用方法窗体onBindViewHolder,该方法仅更新位置0处的值。我只想在条件为真时更新节点子节点。

这是我尝试过的事情:

  public void onBindViewHolder(@NonNull final TvViewHolder tvViewHolder,   
     final int i) {


   formModel=feedbacks.get(i);

   }

 private void updateStatus(final String Reply)
{         databaseReference=FirebaseDatabase.getInstance().
     getReference("USERS_FEEDBACK");
     final Query    findfeedback=databaseReference.orderByChild("email_or_num")
  .equalTo(formModel.getEmail_or_num());


                    findfeedback.addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                            for (DataSnapshot feedback: dataSnapshot.getChildren())

                            {

                              FormModel formModel1=feedback.getValue(FormModel.class);
                                if(formModel1.getFeedback().equals(formModel.getFeedback()) && formModel1.getEmail_or_num().equals(formModel.getEmail_or_num()))
                              {
                                String key=feedback.getKey();
                                databaseReference.child(key).child("status").setValue(Reply);
                                Intent refresh=new Intent(mcontext, StdAppFeedback.class);
                                mcontext.startActivity(refresh);
                                    ((Activity)mcontext).finish();

                                 }

                            }

                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {
                            Toast.makeText(mcontext, databaseError.toString(), Toast.LENGTH_LONG).show();

                        }







    });}

图片在这里:    https://ibb.co/6DfZSHk

0 个答案:

没有答案