RobertApikyan / SegmentedControl

Android SegmentedControl + multi row support
Apache License 2.0
162 stars 30 forks source link

SegmentControl crashes in RecyclerView #14

Closed yhuriez closed 5 years ago

yhuriez commented 5 years ago

Hello, I use a simple instance of SegmentControl (with default adapter) custom view to integrate a "On/off" style switch in a RecyclerView. This RecyclerView is quite complex and the adapter's items can change a lot, and have several type of viewHolder. The problem occurs when you change theses items, for instance :

java.lang.NullPointerException: Attempt to invoke virtual method 'int segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControlControllerComponent.size()' on a null object reference
at segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControl.size(SegmentedControl.java:590)
at segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControl.setSelectedSegment(SegmentedControl.java:448)
at com.example.huriez.sandbox.DataViewHolder$SegmentControlViewHolder.setData(MainActivity.kt:92)
at com.example.huriez.sandbox.DataAdapter.onBindViewHolder(MainActivity.kt:80)
at com.example.huriez.sandbox.DataAdapter.onBindViewHolder(MainActivity.kt:40)

In that state, the componentController contained by the SegmentedControl is null.

I joined a sandbox project with the case reproduced in simplified version, you just need to click on the "Next" button at the bottom of the screen.

Do you know what causes this problem ?

Sandbox.zip

RobertApikyan commented 5 years ago

Hello. Try the new version 'com.github.RobertApikyan:SegmentedControl:1.0.9' . I will close the issue, please fill free to reopen it if any problems occurred.