gpt4 book ai didi

java - 删除的 firebase 值仍然显示在 datasnaphot 中

转载 作者:行者123 更新时间:2023-12-02 11:45:21 26 4
gpt4 key购买 nike

我在 recyclerView 中列出 Firebase 数据,当我滑动 recyclerView 项目时,其值将从 FireBase 中删除。一旦删除,我想将更新的值添加到 arrayList (当然减去删除的值)。我的问题是,即使该值已被删除,它仍然显示在更新的快照中。代码如下。

    ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.LEFT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}

@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
final int position = viewHolder.getAdapterPosition();
if(bidslist.get(position).getUsername().equals(userEmail)){
deleteRef = bidslist.get(position).getMsgID();

mRef.orderByChild("msgID").equalTo(deleteRef).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
deleteKey = childSnapshot.getKey();
mRef.child(deleteKey).removeValue();
}
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}

});

if(bidslist.get(position).getAmount().equals(biggest.toString())){
/*removing data from the second referance. As soon as this is done I would like to update
the reference with the new snapshot, excluding the deleted one.*/

highestRef.child(fbid).removeValue();

mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
/*This is supposed to be the new snapshot*/
BidFirebaseObject obj = dataSnapshot.getValue(BidFirebaseObject.class);
Log.d("dhat", obj.getAmount());
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});

}

//remove it from the adapter
if (direction == ItemTouchHelper.LEFT){
adapter.removeItem(position);
}
}
}

最佳答案

您需要使用notifyDataSetChanged()来通知适配器任何更改:

 adapter.notifyDataSetChanged()

void notifyDataSetChanged() Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.

更多信息请点击:https://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged()

关于java - 删除的 firebase 值仍然显示在 datasnaphot 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48250409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com