设置SetHasFixedSize为true时显示错误,如何解决它。

huangapple go评论74阅读模式
英文:

SetHasFixedSizetrue shows error How to solve it

问题

我有一个带有Firebase后端的RecyclerView我希望在我的视图中将最新的项目显示在顶部我只是在我的LayoutManager中使用了setStackFromEnd(true)但是它显示错误就像这样

![查看图片][1] 

  [1]: https://i.stack.imgur.com/P56YX.png

我的最低SDK版本是16
我使用了<androidx.recyclerview.widget.RecyclerView

这是我的Java代码

MCC = FirebaseDatabase.getInstance().getReference().child("Troll");
recyclerView = (RecyclerView) findViewById(R.id.TrollID_recyclerView);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(new GridLayoutManager(this, 1));

LoadData(categoryId);
英文:

I have a recyclerview with firebase backend. I want to show latest item on top in my view. I just use setStackFromEnd(true); in my layoutmanager but its show error jutst like this

设置SetHasFixedSize为true时显示错误,如何解决它。

My minimum SDK Version is 16
and I used to <androidx.recyclerview.widget.RecyclerView

and this is my java code

MCC=FirebaseDatabase.getInstance().getReference().child(&quot;Troll&quot;);
    recyclerView = (RecyclerView) findViewById(R.id.TrollID_recyclerView);
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(new GridLayoutManager(this, 1));

        LoadData(categoryId);

答案1

得分: 1

你应该首先将最新的项目存储在recycleadapterList中,然后再将其他项目添加到列表中。因为recycleadapter会根据列表项的位置显示项目。

英文:

you should store latest item first in recycleadapterList then your other items add to list.
because recycleadapter show items like list item position

huangapple
  • 本文由 发表于 2020年8月23日 13:28:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63543714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定