[英]Add new item to recyclerview at the top
當我通過以下方式將新商品添加到我的recyclerview中時:
dbHelper.insertAusgabe(tag,datum,ausgabe,menge,kategorie);
Model model = new Model(tag,datum,kategorie,ausgabe,menge);
rvList.add(model);
modelAdapter.notifyItemInserted(rvList.size()-1);
Recyclerview:
modelAdapter = new ModelAdapter(rvList,ScrollingActivity.this);
RecyclerView.LayoutManager layoutManager = new
LinearLayoutManager(ScrollingActivity.this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setFocusable(false);
recyclerView.requestFocus();
那是因為您也將其添加到列表的底部。
rvList.add(model);
應該是rvList.add(0, model);
並通知您的recyclerview不是這樣
modelAdapter.notifyItemInserted(rvList.size()-1);
但是像這個modelAdapter.notifyItemInserted(0);
在您的列表中嘗試使用此代碼。
Collections.reverse(rvList);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.