gpt4 book ai didi

android - 删除项目后 StaggeredGridLayout 管理器,项目分散

转载 作者:行者123 更新时间:2023-11-29 02:37:09 26 4
gpt4 key购买 nike

我正在使用交错网格布局从数据库向回收者 View 显示数据。我遇到了一个问题,在从数据库中删除项目以及从适配器中删除位置后,我遇到了一些项目渲染问题。就像分散的所有在这个地方。这是我的代码

 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_favorite);
ButterKnife.bind(this);
toolbar = (Toolbar) findViewById(R.id.fav_note_toolbar);
setSupportActionBar(toolbar);

noteAdapter = new NoteAdapter(noteModelList, NoteFavoriteActivity.this);
layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(noteAdapter);
touchListenerRecycler();
loadDataAll();


}
private void loadAll() {
noteModelList.clear();

DBManagerFav dbManagerFav = DBManagerFav.getInstance(NoteFavoriteActivity.this);
dbManagerFav.openDataBase();
noteModelList = dbManagerFav.getAllNoteList();
Log.i(TAG, " size : " + noteModelList.size());
noteAdapter = new NoteAdapter(noteModelList, NoteFavoriteActivity.this);
recyclerView.setAdapter(noteAdapter);
noteAdapter.notifyDataSetChanged();

dbManagerFav.closeDataBase();

}


private void deleteOperation() {

DBManagerFav dbManagerFav = DBManagerFav.getInstance(NoteFavoriteActivity.this);
dbManagerFav.openDataBase();

NoteModel noteModel = new NoteModel();
noteModel.setId(noteModelList.get(adapterClickedPosition).getId());

int status = dbManagerFav.deleteNote(noteModelList.get(adapterClickedPosition).getId());
if (status > 0) {

noteAdapter.removeAt(adapterClickedPosition);

}
dbManagerFav.closeDataBase();
loadDataAll();
}
//this belongs to adapter
public void removeAt(int position) {
Log.d(TAG, " removing at position : " + position);
noteModelList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, noteModelList.size());
notifyDataSetChanged();
}

附上前后两张截图在删除项目之前

enter image description here

删除项目后

enter image description here

你能指出我还需要什么吗?

最佳答案

你可以把里面的loadDataAll(){

    layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);

//........}瞧……

关于android - 删除项目后 StaggeredGridLayout 管理器,项目分散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46376702/

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