Kotlin Android debounce

I’ve created a gist with three debounce operators inspired by this elegant solution from Patrick where I added two more similar cases: throttleFirst and throttleLatest. Both of these are very similar to their RxJava analogues (throttleFirst, throttleLatest). throttleLatest works similar to debounce but it operates on time intervals and returns the latest data for each … Read more

Kotlin Android View Binding: findViewById vs Butterknife vs Kotlin Android Extension

There are a lot of ways to access views in Android. A quick overview: My advise would be: findViewById: old school. Avoid. ButterKnife: old school, but less boilerplate and some added functionality. Still lacks compile time safety. Avoid if possible. Kotlin Synthetic: really a elegant cached version of findViewbyId. Better performance and way less boilerplate … Read more

Outdated Kotlin Runtime warning in Android Studio

In your (Project: [projectName]) build.gradle file find this: ext.kotlin_version = ‘x.x.x’ and replace x.x.x with the current version of your Kotlin plugin. In order to check which is the current version of your Kotlin plugin: Go to: Tools -> Kotlin -> Confugure Kotlin Plugin Updates Click “Check again”. After a second you will see the … Read more

NullPointerException when trying to access views in a Kotlin fragment

Kotlin synthetic properties are not magic and work in a very simple way. When you access btn_K, it calls for getView().findViewById(R.id.btn_K). The problem is that you are accessing it too soon. getView() returns null in onCreateView. Try doing it in the onViewCreated method: override fun onViewCreated(view: View, savedInstanceState: Bundle?) { btn_K.setOnClickListener { Log.d(TAG, “onViewCreated(): hello … Read more

Why do I get “unresolved reference” error for my view’s name/ID when I type it in Kotlin?

The ability to refer to a view directly by it’s ID/name in Kotlin is called “synthetic properties” and it is a feature of a project plugin called Kotlin Android Extensions. Google and JetBrains decided to deprecate Kotlin Android Extensions, meaning they no longer support it, and discourage you from using it. Ever since it was … Read more