我在我的项目中使用 FlexboxLayou,但我无法反转从 firebase 获取的数据,我希望它按降序排列。我测试过:
Collections.reverse (list);
它工作,不使用 FlexboxLayou,但由于我的项目有不同的布局,最好的选择是使用 FlexboxLayou。我尝试在recycleview上进行更改:
app: stackFromEnd = "true"
app: reverseLayout = "true"
它没有任何效果。我更改了 FlexboxLayou 中的参数,但有些报错。
FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(context);
flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
flexboxLayoutManager.setJustifyContent(JustifyContent.CENTER);
flexboxLayoutManager.setAlignItems(AlignItems.STRETCH);
flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
如果我将 FlexWrap.WRAP 更改为 FlexWrap.WRAP_REVERSE,适配器也会失败。
使用 Collections.reverse (list) 后出错:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pup, PID: 28144
java.lang.ClassCastException: com.example.pup.Viewholder.Prop.ViewPropU cannot be cast to com.example.pup.Viewholder.Prop.ViewPropS
at com.example.puplica.Adaptadores.AdapatadorProp.onBindViewHolder(AdapatadorProp.java:92)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at com.google.android.flexbox.FlexboxLayoutManager.getFlexItemAt(FlexboxLayoutManager.java:456)
at com.google.android.flexbox.FlexboxLayoutManager.getReorderedFlexItemAt(FlexboxLayoutManager.java:474)
at com.google.android.flexbox.FlexboxHelper.calculateFlexLines(FlexboxHelper.java:429)
at com.google.android.flexbox.FlexboxHelper.calculateHorizontalFlexLines(FlexboxHelper.java:249)
at com.google.android.flexbox.FlexboxLayoutManager.updateFlexLines(FlexboxLayoutManager.java:953)
at com.google.android.flexbox.FlexboxLayoutManager.onLayoutChildren(FlexboxLayoutManager.java:729)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3175)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5911)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2776)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2477)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1544)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7602)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(
在适配器上给出错误。我做了一个很好的研究,我无法得到结果,我试图反转firebase收到的内容,但主题很复杂,我做不到。必须有一个简单的方法来做到这一点。