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 :
I have two ViewHolder : one with the SegmentControl (using Boolean) and another with a simple TextView (using a String)
I configure the RecyclerView adapter items with a simple list containing a Boolean and a String (creating two ViewHolder, first with SegmentControl, second with TextView)
During runtime, I switch items to a list containing only a String (the RecyclerView recycle the TextView ViewHolder)
Then again I change items with the first list, with Boolean and String. The SegmentControl is then recycler, and I get this error :
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.
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.
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 :
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