2016-11-15 69 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

相關問題