flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

fix origin RecyclerView$LayoutParams cast to com.google.android.flexb…

Open LuckyJayce opened this issue 5 years ago • 5 comments

…ox.FlexItem error

java.lang.ClassCastException: android.support.v7.widget.RecyclerView$LayoutParams cannot be cast to com.google.android.flexbox.FlexItem

LuckyJayce avatar Jan 07 '19 01:01 LuckyJayce

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

googlebot avatar Jan 07 '19 01:01 googlebot

Thanks for the PR. Is it possible to add a test for this case?

thagikura avatar Jan 07 '19 07:01 thagikura

has origin LayoutParams

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FlexItemViewHolder {
    var textView = TextView(parent.context);
    textView.setPadding(20, 20, 20, 20)
    textView.id = R.id.textview

    var f = FrameLayout(parent.context)
    f.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
    f.addView(textView)
    return FlexItemViewHolder(f)
} 

or

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FlexItemViewHolder {
    var textView = TextView(parent.context);
    textView.setPadding(20, 20, 20, 20)
    textView.id = R.id.textview

    var f = FrameLayout(parent.context)
    f.layoutParams = FlexboxLayoutManager.LayoutParams(FlexboxLayoutManager.LayoutParams.WRAP_CONTENT, FlexboxLayoutManager.LayoutParams.WRAP_CONTENT)
    f.addView(textView)
    return FlexItemViewHolder(f)
}

LuckyJayce avatar Jan 07 '19 07:01 LuckyJayce

Oh sorry I wanted to say is it possible to add test code to FlexboxLayoutManagerTest?

Also could you accept the CLA?

thagikura avatar Jan 08 '19 04:01 thagikura

I checked your PR in my local, looks like the fix is not enough because the original class's (e.g. FrameLayout) measure is called in FlexboxHelper. And it expects the original class's LayoutParams (FrameLayout.LayoutParams).

Example log.

java.lang.ClassCastException: com.google.android.flexbox.FlexboxLayoutManager$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
at android.widget.FrameLayout.onMeasure(FrameLayout.java:186)
at android.view.View.measure(View.java:22071)
at com.google.android.flexbox.FlexboxHelper.calculateFlexLines(FlexboxHelper.java:470)
at com.google.android.flexbox.FlexboxHelper.calculateHorizontalFlexLines(FlexboxHelper.java:244)
at com.google.android.flexbox.FlexboxLayoutManager.updateFlexLines(FlexboxLayoutManager.java:958)
at com.google.android.flexbox.FlexboxLayoutManager.onLayoutChildren(FlexboxLayoutManager.java:734)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:498)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2496)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2212)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

thagikura avatar Jan 15 '19 08:01 thagikura