firebase,如何更新密钥

时间:2016-07-11 07:25:02

标签: android firebase firebase-realtime-database firebaseui

在更新存储桶(密钥)中的对象时遇到一些困难。 在持久性时,我push()一个节点的对象列表(在本例中为Trip)。 之后,我检索了它,并在单击按钮时进行更新(在这种情况下,更新出价信息)。我似乎无法找到一种简单的方法,除非我之前推过旅程,我必须手动调用getkey(),然后将自动生成的uid更新为对象Trip本身。有没有想过轻松完成它?感谢

mFirebaseAdapter = new FirebaseRecyclerAdapter<Trip,
            TripViewHolder>(
            Trip.class,
            R.layout.item_message,
            TripViewHolder.class,
            mFirebaseDatabaseReference.child(CHILD_TRIPS)) {

        @Override
        protected void populateViewHolder(TripViewHolder viewHolder, final Trip model, int position) {

            viewHolder.btnTakeNow.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {

                     Bid bidAtReserved = new Bid(mDriverCarInfo, model, MY_PRICE);

                     mFirebaseDatabaseReference.child(CHILD_TRIPS)
                             //here, I want to update the bidding to this trip, but 
                             //I can't get the uid of the trip, unless I had 
                             //manually recorded at the time of pushing the trip
                             .child(model.getUid()) 
                              .child("bids").push().setValue(bidAtReserved);


                 }
            });
        }
    };

2 个答案:

答案 0 :(得分:4)

我不确定你要完成什么(相关JSON的片段 - 文字,而不是屏幕截图 - 会有所帮助)。但我最好的猜测是你正在寻找rest_auth.views.UserDetailsView

getRef()

答案 1 :(得分:0)

FirebaseRecylerAdapter有一个名为parseSnapShot的覆盖,您可以像这样挂钩。我不知道更好的解决方案 - 所以希望有人能提供更好的解决方案。

mFirebaseAdapter = new FirebaseRecyclerAdapter<Trip,
                TripViewHolder>(
                Trip.class,
                R.layout.item_message,
                TripViewHolder.class,
                mFirebaseDatabaseReference.child(CHILD_TRIPS)) {

        @Override
        protected Trip parseSnapshot(DataSnapshot snapshot) {

            Trip trip = super.parseSnapshot(snapshot);
            trip.setDbKey(snapshot.getKey());

            return trip;
        }

        @Override
        protected void populateViewHolder(TripViewHolder viewHolder, final Trip model, int position) {

            viewHolder.btnTakeNow.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {

                     Bid bidAtReserved = new Bid(mDriverCarInfo, model, MY_PRICE);

                     mFirebaseDatabaseReference.child(CHILD_TRIPS)
                             //here, I want to update the bidding to this trip, but I can't get the uid of the trip, unless I had manually recorded at the time of pushing the trip
                             .child(model.getUid()) 
                              .child("bids").push().setValue(bidAtReserved);


                 }
            });
        }
    };