如何从RecyclerView中删除项目并从Firebase中的两个孩子中读取

时间:2016-11-15 11:35:05

标签: android firebase firebase-realtime-database firebaseui

我是Android开发的新手,试图弄清楚如何做两件事。

  1. 使用关闭按钮删除RecyclerView和Firebase
  2. 中的项目
  3. 从数据库中的两个子项中检索项目。在我的代码中,我只能从一个孩子(offer_Rides)中检索,但我想从另一个名为“#34;用户"”的孩子中检索。
  4. enter image description here

    public class WallActivity extends AppCompatActivity {
    
    
    private Button ivClose;
    
    private RecyclerView offerList;
    
    private DatabaseReference mDatabase;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wall);
    
        mDatabase = FirebaseDatabase.getInstance().getReference().child("Offer_Rides");
    
    
        ivClose = (Button) findViewById(R.id.ivClose);
     //   ivClose.setOnClickListener((View.OnClickListener) this);
    
    
        offerList = (RecyclerView) findViewById(R.id.offerList);
        offerList.setHasFixedSize(true);
     offerList.setLayoutManager(new LinearLayoutManager(this));
    
    }
    
    @Override
    protected void onStart() {
        super.onStart();
    
      FirebaseRecyclerAdapter<OfferPost, OfferPostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<OfferPost, OfferPostViewHolder>(
              OfferPost.class,
              R.layout.offer_list_row,
              OfferPostViewHolder.class,
              mDatabase
    
              ){
          @Override
          protected void populateViewHolder(OfferPostViewHolder viewHolder, OfferPost model, int position) {
                viewHolder.setFirstname(model.getFirstname());
              viewHolder.setLastname(model.getLastname());
              viewHolder.setPhone(model.getPhone());
              viewHolder.setPrice(model.getPrice());
              viewHolder.setSeats(model.getSeats());
              viewHolder.setLocation(model.getLocation());
            viewHolder.setDestination(model.getDestination());
          }
      };
    

    offerList.setAdapter(firebaseRecyclerAdapter);     }

    public static class OfferPostViewHolder extends RecyclerView.ViewHolder{
    
        View mView;
        public OfferPostViewHolder(View itemView) {
            super(itemView);
    
            mView = itemView;
        }
    
        public void setFirstname(String firstname){
            TextView post_firstname = (TextView) mView.findViewById(R.id.tvFirstname);
            post_firstname.setText(firstname);
    
        }
        public void setLastname(String lastname){
            TextView post_firstname = (TextView) mView.findViewById(R.id.tvLastname);
            post_firstname.setText(lastname);
    
        }
        public void setPhone(String phone){
            TextView post_phone = (TextView) mView.findViewById(R.id.tvPhone);
            post_phone.setText(phone);
    
        }
        public void setPrice(String price){
            TextView post_price = (TextView) mView.findViewById(R.id.tvCash);
            post_price.setText(price);
    
        }
        public void setSeats(String seats){
            TextView post_seats = (TextView) mView.findViewById(R.id.tvSeats);
            post_seats.setText(seats);
    
        }
        public void setLocation(String location){
            TextView post_location = (TextView) mView.findViewById(R.id.tvLocation);
            post_location.setText(location);
    
        }
        public void setDestination(String destination){
          TextView post_destination = (TextView) mView.findViewById(R.id.tvDestination);
        post_destination.setText(destination);
    
    }
    
    }
    

    }

1 个答案:

答案 0 :(得分:2)

如果要删除firebase中的用户值,请使用此代码

DatabaseReference databaseReference = firebaseDatabase.getReference().child("Users");
    databaseReference.removeValue();