第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用按鈕從 firebase 列表適配器和 firebase 中刪除項(xiàng)目

如何使用按鈕從 firebase 列表適配器和 firebase 中刪除項(xiàng)目

慕容森 2023-10-13 09:57:15
我有一個(gè)從 Firebase 數(shù)據(jù)庫讀取數(shù)據(jù)并在 Firebase 列表適配器中顯示數(shù)據(jù)的活動(dòng)。列表視圖中的每個(gè)項(xiàng)目都有 2 個(gè)編輯文本和一個(gè)用于從列表視圖和 Firebase 數(shù)據(jù)庫中刪除項(xiàng)目的按鈕。下面是顯示 firebase 列表適配器的代碼      adapter =new FirebaseListAdapter <TravelDetails>   ( options){  protected void populateView(View v, TravelDetails model, int position) {Button delete=(Button)v.findViewById(R.id.button_accept);final TextView z=(TextView)v.findViewById(R.id.dropoff);final TextView text=(TextView)v.findViewById(R.id.txref);text.setText(model.getTxt_Ref()); z.setText(model.getDropoffspot()); delete.setOnClickListener(new View.OnClickListener() {     @Override     public void onClick(View v) {.....列表視圖工作正常。數(shù)據(jù)是從 firebase 加載的,但我希望能夠使用此按鈕刪除來從列表視圖和 firebase 數(shù)據(jù)庫中刪除項(xiàng)目。我做了研究,只找到了點(diǎn)擊項(xiàng)目而不使用按鈕的方法,一個(gè)例子是這個(gè)Android studio 從 listview 和 firebase 中刪除項(xiàng)目 ,但我不知道如何將原理應(yīng)用到與數(shù)據(jù)庫中的項(xiàng)目關(guān)聯(lián)的按鈕。請(qǐng)?zhí)峁﹨f(xié)助下面是我的適配器類的代碼 public class TravelDetails {  private String dropoffspot;    private String txt_Ref;    public TravelDetails(){    }    public String getDropoffspot(){    return dropoffspot;     }    public void setDropoffspot(String dropoffspot){    this.dropoffspot=dropoffspot;    }    public String getTxt_Ref() {    return txt_Ref;    }       public void setTxt_Ref(String txt_Ref) {       this.txt_Ref = txt_Ref;     }  } 
查看完整描述

2 回答

?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以在適配器內(nèi)執(zhí)行此操作


// make this function inside your adapter


protected void populateView(View v, ArrayList<TravelDetails> models, final int position) {

    Button delete=(Button)v.findViewById(R.id.button_accept);

    final TextView z=(TextView)v.findViewById(R.id.dropoff);

    final TextView text=(TextView)v.findViewById(R.id.txref);

    text.setText(model.getTxt_Ref());

    z.setText(model.getDropoffspot());

    delete.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v) {

            // code to delete from firebase

            models.remove(position); // delete from adapter array list

            notifyDataSetChanged(); // refresh adapter

        }

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-10-13
?
MM們

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊

我找到了如何解決我的問題。我只是將其添加到單擊方法的刪除按鈕中。

         public void onClick(View v) {
         DatabaseReference item=adapter.getRef(position) ;
         item.removeValue();

} }) ;


查看完整回答
反對(duì) 回復(fù) 2023-10-13
  • 2 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)