它在firebase数据库中删除。.但是我必须登录并注销以查看回收者视图以删除该项目或更改活动布局,例如返回并单击返回回收者视图活动页面以清除该项目。 即使已将其删除,该项目也在那里。从数据库中删除该项目后,我将在回收器视图中清除这些项目。
Context context;
List<Planner> MainImageUploadInfoList;
public RecyclerPlanner(Context context, List<Planner> TempList) {
this.MainImageUploadInfoList = TempList;
this.context = context;
SharedPreferences userlogin = context.getSharedPreferences("userlogin",0);
userid = userlogin.getString("UserID",null);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final Planner directory = MainImageUploadInfoList.get(position);
holder.deldir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
DatabaseReference planner = myRef.child("Planner");
DatabaseReference planner1 = planner.child(userid);
date = directory.getDate();
locationid = directory.getLocationID();
date1 = date.replace("/", "");
DatabaseReference planner2 = planner1.child(date1);
planner2.child(locationid).removeValue();
}
});
}
@Override
public int getItemCount() {
return MainImageUploadInfoList.size();
}
答案 0 :(得分:0)
在删除方法中使用它-
MainImageUploadInfoList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, getItemCount());