kotlin-android-extensions

kotlin - How synthetic property initialise view?

本秂侑毒 提交于 2019-12-13 09:09:45
问题 I used synthetic property in my code.But wondering for how and when it actually initialise each view in android. We simply provide import and access each view by its id. When it allocate memory for view object? 回答1: This is easy enough to investigate by decompiling a Kotlin file where you use Kotlin Android Extensions. (You can do this by going to Tools -> Kotlin -> Show Kotlin Bytecode and then choosing Decompile in the pane that appears.) In short, it's nothing magical, it just uses

How to use syntethic properties when you have the same layout included twice

*爱你&永不变心* 提交于 2019-12-13 03:56:43
问题 Normally, when I need to include the same layout in one screen, I would wrap this layout in two different containers with a different id and call findViewById on those two parents but I don't know if and how I could achieve the same result with kotlin's syntethic properties. Just to be more clear: I am in the situation where fragment_xyz.xml is composed like this: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android

How do I turn AutoImport on in Android Studio?

一曲冷凌霜 提交于 2019-12-13 03:47:34
问题 In the build your first Android app Kotlin instructions it is shown to use File-> Other Settings -> Default Settings to enable auto-imports. However this option is missing in Android Studio 3.4.2 回答1: File->Other Settings->Settings for New Projects -> Other Settings -> Auto Import Then I checked Add unambiguous imports on the fly. 来源: https://stackoverflow.com/questions/57467501/how-do-i-turn-autoimport-on-in-android-studio

NoSuchMethodError using @Parcelize Annotation in Kotlin

谁都会走 提交于 2019-12-12 10:45:57
问题 I'm currently trying out the experimental (which might be why it's not working...) @Parcelize annotation to generate Parcelable code. Most types seem to be working fine, but I'm having issues with Serializable s throwing a NoSuchMethodError : 10-05 13:55:18.549 20808-20808/com.app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.app, PID: 20808 java.lang.NoSuchMethodError: No virtual method writeSerializable(Ljava/util/Date;)V in class Landroid/os/Parcel; or its super classes (declaration

Kotlin Android debounce

懵懂的女人 提交于 2019-12-12 07:47:33
问题 Is there any fancy way to implement debounce logic with Kotlin Android? I'm not using Rx in project. There is a way in Java, but it is too big as for me here. 回答1: You can use kotlin coroutines to achieve that. Here is an example. Be aware that coroutines are experimental at kotlin 1.1+ and it may be changed in upcoming kotlin versions. UPDATE Since Kotlin 1.3 release, coroutines are now stable. 回答2: Thanks to https://medium.com/@pro100svitlo/edittext-debounce-with-kotlin-coroutines

Firebase DataSnapshot getValue does not set properties on init body

巧了我就是萌 提交于 2019-12-11 06:02:07
问题 I have a datasnopshot returned from my firebase database and set it up to parse the json to my model class. override fun onDataChange(snapshot: DataSnapshot) { if(snapshot.exists()){ newReleases.clear() for(d in snapshot.children){ val media = d.getValue(PlayableMedia::class.java) newReleases.add(media!!) } newReleasesAdapter!!.notifyDataSetChanged() } } Now this works if I am not doing anything during initialization. My problem is when I do something during initialization, my properties on

What is the difference between arrayListOf and mutableListOf , which one is better? [duplicate]

大憨熊 提交于 2019-12-11 01:47:52
问题 This question already has answers here : Difference between ArrayList<String>() and mutableListOf<String>() in Kotlin (4 answers) Closed 2 years ago . I am trying to use collections in Kotlin and got confused between arrayListOf and mutableListOf, which one should we use and why? 回答1: Either is fine, the only difference between calling the two is expressing your intent. ArrayList is a concrete implementation of MutableList , and mutableListOf , as of Kotlin 1.1, also returns an ArrayList . Do

Android - View instance gets null on screen rotation

对着背影说爱祢 提交于 2019-12-10 16:42:42
问题 I am using Kotlin Android Extension to access view directly by their id. I have a progress bar which I access directly in fragment using id i.e progress_bar <ProgressBar android:id="@+id/progress_bar" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="15dp" android:indeterminate="true"/> In fragment, I am showing and hiding it with this code progress_bar.visibility = if (visible) View.VISIBLE else View.GONE It is working perfectly

Varargs Kotlin Java interop not working properly

混江龙づ霸主 提交于 2019-12-10 02:12:03
问题 For the makeSceneTransitionAnimation there are two static functions public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity, View sharedElement, String sharedElementName) and public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity, Pair<View, String>... sharedElements) The first function call works properly in Kotlin but when calling the second one, both these calls return errors val imageTransition = Pair<View, String>(imageView,

Kotlin Android Extension layouts from library module cannot be resolved

拟墨画扇 提交于 2019-12-10 00:58:44
问题 I have my buyer , seller module and a common module. Few layouts which are used in both buyer and seller module are placed in common module. common -> layout_toolbar.xml buyer -> activity_sell.xml -> <LinearLayout> <include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module --> </LinearLayout> seller -> activity_buy.xml -> <RelativeLayout> <include layout="@layout/layout_toolbar" /> <!-- layout_toolbar.xml is from common module --> </RelativeLayout> buyer ->