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

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

當(dāng)我點(diǎn)擊“刪除”按鈕時(shí),如何刪除數(shù)據(jù)庫上的一個(gè)項(xiàng)目?

當(dāng)我點(diǎn)擊“刪除”按鈕時(shí),如何刪除數(shù)據(jù)庫上的一個(gè)項(xiàng)目?

慕哥9229398 2022-09-28 16:03:32
我是安卓工作室的新手,對于我的安卓應(yīng)用程序,我使用的是火庫。我想在單擊按鈕 時(shí)從數(shù)據(jù)庫中刪除一個(gè)項(xiàng)目。delete(btnDelete)    String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();    Query query= FirebaseDatabase.getInstance()            .getReference().child("users").child(uid).child("foto");        public ViewHolder(@NonNull View itemView) {            super(itemView);            foto_root=itemView.findViewById(R.id.foto_root);            tvNameF=itemView.findViewById(R.id.tvNameF);            tvPhoneF=itemView.findViewById(R.id.tvPhoneF);            tvAdressF=itemView.findViewById(R.id.tvAdressF);            tvMailF=itemView.findViewById(R.id.tvMailF);            tvNoteF=itemView.findViewById(R.id.tvNoteF);            btnDelete=itemView.findViewById(R.id.btnDelete);        }        public void setTvNameF(String tvNameFs){            tvNameF.setText(tvNameFs);        }        public void setTvPhoneF(String tvPhoneFs){            tvPhoneF.setText(tvPhoneFs);        }    }    /*    get on dataBase     */    private void fetch() {        FirebaseRecyclerOptions<Foto> options=                new FirebaseRecyclerOptions.Builder<Foto>().setQuery(query, snapshot -> new Foto(                snapshot.child("id").getKey(),                snapshot.child("name").getValue().toString(),                snapshot.child("phone").getValue().toString(),                snapshot.child("adress").getValue().toString(),                snapshot.child("email").getValue().toString(),                snapshot.child("note").getValue().toString())).build();        adapter = new FirebaseRecyclerAdapter<Foto, FotoActivity.ViewHolder>(options) {            @NonNull            @Override            public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {                View view = LayoutInflater.from(parent.getContext())                        .inflate(R.layout.foto_item,parent,false);                return new ViewHolder(view);            }        };我想從數(shù)據(jù)庫中刪除一個(gè)項(xiàng)目,而不是所有數(shù)據(jù)庫。foto
查看完整描述

1 回答

?
忽然笑

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

只需在刪除函數(shù)中使用以下命令,這將刪除“phone”節(jié)點(diǎn)的值。您需要知道要?jiǎng)h除的用戶的 uid,否則您可以將其替換為數(shù)據(jù)庫節(jié)點(diǎn)引用,但隨后會從所有用戶 ID 中刪除電話。基本上,您將偵聽 foto 節(jié)點(diǎn),獲取所有推送 ID 并循環(huán)訪問推送 ID 以刪除所需的節(jié)點(diǎn)。


聲明變量


private static final String TAG = "TestActivity";

private DatabaseReference fbDbRef;

在創(chuàng)建


final String uid = "youruid";

fbDbRef = FirebaseDatabase.getInstance().getReference().child("users")

         .child(uid).child("foto");

您的職能


private void delete() {


fbDbRef.addListenerForSingleValueEvent(new ValueEventListener() {


        @Override

        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {


            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {


                final String pushKey = snapshot.getKey();

                Log.d(TAG, "pushKey: " + pushKey);

                fbDbRef.child(pushKey).child("phone").removeValue();


            }


        }


        @Override

        public void onCancelled(@NonNull DatabaseError databaseError) {


        }

    });


}


查看完整回答
反對 回復(fù) 2022-09-28
  • 1 回答
  • 0 關(guān)注
  • 142 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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