LoadingButtonAndroid
LoadingButtonAndroid copied to clipboard
lateinit property initialState has not been initialized
Hi,
I encountered a problem with CircularProgressButton I wanted to try the behavior of my button, so I called startAnimation() in the onCreate() but I get this exception : lateinit property initialState has not been initialized If I call it after (like in an onClickListener) it works fine
As sample I used a simple project with an empty activity :
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.startAnimation()
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<br.com.simplepass.loadingbutton.customViews.CircularProgressButton
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
kotlin 1.3 AndroidX LoadingButtonAndroid 2.0.7
Best regards
having the same issue when calling dispose()
So, for those who have the same issue I found a workaround :
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// This will manually initialize the 'initialState' field
button.saveInitialState()
button.startAnimation()
}
}
Yes, I am getting the same issue. I have a CircularProgressButton inside a DialogFragment.
It appears that it is only observing the lifecycle of the underlying activity, therefore, it crashes as soon as the activity ends, as the button has been disposed of but the lifecycle listener is still alive.
Any ideas for a workaround?
I have resolved this issue by adding the bottom programmatically and passing in the context of the Dialog Fragment instead of the activity context it seems to be receiving via XML.
Adding it like so:
val height = (35).scaleToDP(safeContext)
val width = (150).scaleToDP(safeContext)
val layoutParams = LinearLayout.LayoutParams(width, height)
val button = CircularProgressButton(safeContext)
button.layoutParams = layoutParams
button.elevation = (7).scaleToDP(safeContext).toFloat()
val drawable = ContextCompat.getDrawable(safeContext, R.drawable.download_button_shape)
button.background = drawable
button.text = getString(R.string.offline_map_download_text)
button.setOnClickListener {
processDownloadDeleteButtonTapped(button)
}
return button
I have no issues now.
It took me 3 months to see this issue o.O. I'll be taking a look
Use the version 2.1.3
, this is fixed in that one =]
I have the same issue with version 2.2.0, did the bug come back?
I have the same issue with version 2.2.0, did the bug come back?
Having the same issue. Please use
button.saveInitialState()