RobertApikyan / SegmentedControl

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

Android Studio Internal error? #25

Closed lpbas closed 4 years ago

lpbas commented 5 years ago

Hello. I would like to thank you for this library, it brings a missing functionality of the platform and its very easy to use!

I've noticed today that when I was trying to add an OnSegmentClickListener my Android Studio is throwing an internal error you can see here.

I've also tried updating the library to the latest version. This code was working perfectly fine two days ago, and I don't know if this is the libraries fault or Andorid Studio's... Ι've updated to the latest kotlin but it was working after the update as well. Do you have any idea what could cause this? I tried cleaning my project, invalidating caches, etc, but the error is still there. Any help is greatly appreciated

RobertApikyan commented 5 years ago

Hi, could you please send a code snippet where you configure segmented control

lpbas commented 5 years ago

The XML is this:

<segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControl android:id="@+id/newspapersSegmentedControl" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="@dimen/default_margin_triple" android:layout_marginTop="@dimen/default_margin_double" android:layout_marginEnd="@dimen/default_margin_triple" app:columnCount="2" app:distributeEvenly="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/newspapersFragmentTitleTextView" app:radius="8dp" app:segments="@array/newspaper_types" app:selectedBackgroundColor="@color/blue" app:selectedStrokeColor="@color/blue" app:selectedTextColor="@color/white" app:textVerticalPadding="6dp" app:unSelectedBackgroundColor="@color/white" app:unSelectedStrokeColor="@color/blue" app:unSelectedTextColor="@color/blue"/>

It's in a ConstraintLayout so the 0dp width is to match constraints.

The newspaper_types array is:

`<?xml version="1.0" encoding="utf-8"?>

Sports Politics ` and my configuration in code is just `view.newspapersSegmentedControl.addOnSegmentClickListener { segmentViewHolder, isSelected, isReselected -> updateVisibleNewspapers() } view.newspapersSegmentedControl.setSelectedSegment(0)` in order to update what i'm showing on screen, and pre-select the first segment. I'm not sure if its the libraries fault or Android Studio's... Thank you for your help!
RobertApikyan commented 5 years ago

Look at the appOnSegmentClickListener, it might have only one argument (segmentViewHolder), but in your code there is 3 (segmentViewHolder, isSelected, isReselected). It might be like this

segmentControl.addOnSegmentClickListener { viewHoler->  
                   ... 
}

For handling segment selections use

segmentControl.addOnSegmentSelectListener { segmentViewHolder, isSelected, isReselected -> 
                   ...
}
RobertApikyan commented 5 years ago

is this fixed ?

lpbas commented 5 years ago

Thank you for your help Robert. I've replaced the code with the method you've suggested. Unfortunately, Android Studio is still giving me this error, however, I found that after a clean build, then the first build succeeds and the rest of them are failing. I'll have to do sombre digging and get back to you, I think there is something wrong with Android Studio and not your library.

Have you ever faced a similar issue before?

RobertApikyan commented 5 years ago

this is one of the previous version, try this one and let's see if the error will remain 'com.github.RobertApikyan:SegmentedControl:1.0.9'

RobertApikyan commented 5 years ago

Also try this option too, open "Project Settings" -> Modules -> set "Source Compatibility" and "Target Compatibility" to 1.8 (Java 8)

Screen Shot 2019-07-01 at 7 41 15 PM
lpbas commented 4 years ago

I uncommented the code after all these months of not using it and it seems to be working now, with all the android studio updated I've done. I still don't know if it was the libraries fault or the IDE's, most probably the later. Thank you for taking the time to look into this :)