kotlin

Kotlin in xml onClick not work

孤者浪人 提交于 2021-01-27 05:59:36
问题 I learning kotlin, and now for me not cearly some moment. I have xml <ImageView android:id="@+id/aries" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:tag="1" android:onClick="clickItemHoro" android:src="@drawable/aries" /> and fragment class ChooseYourHoroscope : Fragment(){ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment

Kotlin in xml onClick not work

元气小坏坏 提交于 2021-01-27 05:59:17
问题 I learning kotlin, and now for me not cearly some moment. I have xml <ImageView android:id="@+id/aries" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:tag="1" android:onClick="clickItemHoro" android:src="@drawable/aries" /> and fragment class ChooseYourHoroscope : Fragment(){ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment

viewModelScope not cancelled

拜拜、爱过 提交于 2021-01-27 05:56:20
问题 After watching Sean's explanation on Android (Google I/O'19) I've tried the same: init{ viewModelScope.launch { Timber.i("coroutine awake") while (true){ delay(2_000) Timber.i("another round trip") } } } Unfortunately onCleared it's called when the activity is killed but not when it's put in background ("when we move away from the Activity...", background is "moving away" imho ^^). And I get the following output: > ---- Activity in Foreground > 12:41:10.195 TEST: coroutine awake > 12:41:12

How can I run the Kotlin REPL kotlinc-jvm or kotlinc

ε祈祈猫儿з 提交于 2021-01-27 05:44:09
问题 I am completely new to Kotlin, and I am trying to run the Kotlin REPL. Following this, and considering I am using OS X, and I have tried this: $ /usr/local/bin/kotlinc-jvm which is equivalent to: $ kotlinc-jvm Then in the following link, I found that a nicer way to run it is: $ kotlinc Is there any differences between this two commands, and which one should I choose? 回答1: If you look inside the kotlinc-jvm files, they actually just launch the kotlinc that's in the same folder they are in, and

How to fix initialization error for DefaultKotlinSourceSetKt?

谁都会走 提交于 2021-01-27 05:36:28
问题 With project build (or simple Gradle sync), I have the following error: Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt This error shows after change gradle wrapper version from 4.10 to 6.2.2 (because min gradle wrapper version required 5.6.4, but with 5.6.4 Apollo has error "Access denied" for build folder) Sorry for mistakes, my English is very bad( My build.gradle: apply plugin: 'com.android

Convert callback hell to deferred object

ⅰ亾dé卋堺 提交于 2021-01-27 05:28:50
问题 Background : So, I have a pretty big project with a lot of API functions. I'm thinking of completely moving to coroutines, but as they are implemented as Callback and not Deferred , I can not use them efficiently. For instance: I would like to do apiCallOne() , apiCallTwo() and apiCallThree() async and call .await() to wait till the last request is completed before changing UI. Now the project is structured like this: At the very bottom (or top) is ApiService.java : interface ApiService {

Convert callback hell to deferred object

隐身守侯 提交于 2021-01-27 05:25:50
问题 Background : So, I have a pretty big project with a lot of API functions. I'm thinking of completely moving to coroutines, but as they are implemented as Callback and not Deferred , I can not use them efficiently. For instance: I would like to do apiCallOne() , apiCallTwo() and apiCallThree() async and call .await() to wait till the last request is completed before changing UI. Now the project is structured like this: At the very bottom (or top) is ApiService.java : interface ApiService {

Convert callback hell to deferred object

烈酒焚心 提交于 2021-01-27 05:25:26
问题 Background : So, I have a pretty big project with a lot of API functions. I'm thinking of completely moving to coroutines, but as they are implemented as Callback and not Deferred , I can not use them efficiently. For instance: I would like to do apiCallOne() , apiCallTwo() and apiCallThree() async and call .await() to wait till the last request is completed before changing UI. Now the project is structured like this: At the very bottom (or top) is ApiService.java : interface ApiService {

Android EditText error message popup text not showing

末鹿安然 提交于 2021-01-27 05:16:22
问题 I'm having an issue in my app where the error popup on EditTexts shows but the text is not visible. It looks something like this: This happens with all the EditText s in my app. Here's an example layout XML Layout: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"

'this' is not defined in this context

偶尔善良 提交于 2021-01-27 04:54:30
问题 How can I solve the following case? interface I class A(i: I) class C : I, A(this) // << --- 'this' is not defined in this context In short, I want to pass the class instance to super class constructor. Is it possible in Kotlin? P.S. All the answers are good and technically correct. But let's give a concrete example: interface Pilot { fun informAboutObstacle() } abstract class Car(private val pilot: Pilot) { fun drive() { while (true) { // .... if (haveObstacleDetected()) { pilot