2016-11-15 71 views
0

刚刚接触android开发的人员正试图弄清楚如何做两件事。如何删除RecyclerView中的项目和从Firebase中的两个子项读取

  1. 使用关闭按钮,从数据库中的两个孩子删除一个RecyclerView和火力地堡
  2. 检索项目的项目。在我的代码中,我只能从一个孩子(offer_Rides)中检索,但我想从另一个名为“用户”的孩子中检索。

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); 

} 

} 

}

回答

2

如果你想删除的火力点使用的用户价值这个代码

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

不要我把这个按钮onClickListener里面? –

+0

是加入内部onclick监听器 –

+0

@Ajinkumar我如何从Firebase中删除图片? – Erum

相关问题