我有一个RecyclerView
活动,当用户从他们的设备打开此活动时,名称会添加到 recyclerview。
这是我的代码:
mDatabase.child(rID).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Map<String, String> map = (Map<String, String>) dataSnapshot.getValue();
pA = map.get("pName");
uA = map.get("pUrl");
String cLatS = map.get("cLat").trim();
currentLtAU = Double.parseDouble(cLatS);
String cLngS = map.get("cLng").trim();
currentLnAU = Double.parseDouble(cLngS);
layout.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.INVISIBLE);
prepareData();
} else {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Some error occurred. Please retry!", Snackbar.LENGTH_SHORT);
snackbar.show();
onBackPressed();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Log.d("childRemoved", dataSnapshot.getKey());
aModelClass = new AModelClass(pA, uA, String.valueOf(currentLtAU), String.valueOf(currentLnAU), null, s, v, availableFrom, rID, userID2, noa);
aFastItemAdapter.remove(aFastItemAdapter.getAdapterItemCount() - 1);
aList.setAdapter(aFastItemAdapter);
aList.smoothScrollToPosition(0);
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
这是prepareData();
方法:-
public void prepareData() {
aModelClass = new AModelClass(pA, uA, String.valueOf(currentLtAU), String.valueOf(currentLnAU), null, s, v, availableFrom, rID, userID2, noa);
aFastItemAdapter.add(aModelClass);
aList.setAdapter(aFastItemAdapter);
aList.smoothScrollToPosition(0);
}
名称正在被添加,但问题是它们并没有像在数据库中那样被删除。就像在数据库中一样,"John"
被删除了,但在列表中,最后一项无论是什么都被删除了。
如何从列表中删除从数据库中删除的完全相同的名称?