kotlin

Different background for a button's states in Kotlin

浪子不回头ぞ 提交于 2021-01-27 19:19:00
问题 I have a button in my project that works like this: The button has 3 different designs for each state - disabled ( state_enabled="false" ), enabled, pressed. This button remains disabled if no file is selected, and has a particular design for it. Although, when file is selected, this button becomes enabled and switches to a different design. And the button's highlight color is possible to see every time when the button is enabled and pressed. What I have tried so far: <?xml version="1.0"

Access Binding Adapters in multi module project

一世执手 提交于 2021-01-27 19:16:00
问题 I've got a multi module project where the app module contains my binding adapters and my feature module depends on my app module since it is a dynamic feature module. App (contains binding adapters) ----> Dynamic feature module (where the layout is present) I have databinding and kapt enabled in all the modules. I'm unable to build the app successfully. Android Studio gives me the following error, error: cannot find symbol import com.app.module1.databinding.FeatureItemBindingImpl; Layout file

Android Studio : Could not set process working directory to “new directory”

牧云@^-^@ 提交于 2021-01-27 18:44:57
问题 I am doing a project using Android Studio. After change the directory to another place. I got an Error "Could not set process working directory to [my old directory path] : could not setcwd() (errno 2: No such file or directory)" 回答1: Follow below steps. Close android studio. Delete the .idea folder on your project folder. Start android studio and open your project. worked for me. 回答2: Restart Android studio and open your project from the new directory 来源: https://stackoverflow.com/questions

Trying to impact RecyclerView items via EventBus

狂风中的少年 提交于 2021-01-27 17:18:25
问题 I'm trying to post an EventBus event from an recycler item view class and subscribe to it in the same class so that the event is grabbed by ALL the recycler items. Now in more detail: I have a RecyclerView where each item (FriendListItem.kt) has a context menu. Only one context menu should be shown at a time. That means that I need to close another item's context menu if its visible. I chose to use the org.greenrobot.eventbus which we already widely used in our app. In the item class, when

Android Room Fetch data with dynamic table name

倖福魔咒の 提交于 2021-01-27 14:46:20
问题 Is it possible to fetch data by passing the table name as a parameter ? Something like this. @Query("SELECT id, name from :tableName") fun getData(tableName: String): List<RandomModel> 回答1: Try this @Dao interface RawDao { @RawQuery List<RandomModel> getData(SupportSQLiteQuery query); } SimpleSQLiteQuery query = new SimpleSQLiteQuery("SELECT * FROM "+ tablename); List<RandomModel> models = rawDao.getUserViaQuery(query); 回答2: I think Room does not support dynamic tableName . We have two ways:

How to send array of objects in retrofit multipart request

倾然丶 夕夏残阳落幕 提交于 2021-01-27 13:42:13
问题 I want to send array objects with multipart data. I tried many ways but it is not working. My issue with the contributor parameter. Server says. contributor.0.id is required & contributor.0.role is required and so on for remaining items in the list. Server reads that there is a contributor array and it has items but he can't extract it for some reason. Any help please? @Multipart @POST("project/create") fun createProject( @Header("Authorization") token: String, @Part("title") title: String,

hibernate jpa projection with @Query

不问归期 提交于 2021-01-27 13:04:57
问题 Most of the examples I've seen is using entityManager.createQuery or .createNativeQuery etc. Is there a way to have something like the following working? data class SummaryDto(val employeeName: String, val employerName: String) @Query("select e.name as employeeName, emp.name as employerName " + "from Employer e " + "inner join Employee emp on emp.employer_id = e.id ", nativeQuery = true) fun findSummaries(): List<SummaryDto> When I ran the above code I got this error No converter found

Typealias - Combine Multiple Interfaces in Kotlin

拜拜、爱过 提交于 2021-01-27 13:00:33
问题 I'm a bit rusty with protocol composition in Kotlin, I'd just like to combine multiple interfaces by declaring a custom typealias : // This doesn't work typealias MyType = (ReadableInterface && WritableInterface) Any ideas? In Swift , I would do it this way: typealias MyType = ReadableInterface & WritableInterface In Objective C , I would do it this way: typedef <ReadableInterface, WritableInterface> MyType; 回答1: Why not just create new interface? interface MyType : ReadableInterface,

hibernate jpa projection with @Query

做~自己de王妃 提交于 2021-01-27 13:00:22
问题 Most of the examples I've seen is using entityManager.createQuery or .createNativeQuery etc. Is there a way to have something like the following working? data class SummaryDto(val employeeName: String, val employerName: String) @Query("select e.name as employeeName, emp.name as employerName " + "from Employer e " + "inner join Employee emp on emp.employer_id = e.id ", nativeQuery = true) fun findSummaries(): List<SummaryDto> When I ran the above code I got this error No converter found

(imutable collection is mutable) returns true in Kotlin

我的梦境 提交于 2021-01-27 12:55:18
问题 Why this is happening in Kotlin: val list: List<Int> = listOf(1, 2, 3)// Immutable list if(list is MutableCollection<*>){// why this "if" condition is true? println("is mutable")// this line is printed (list as MutableCollection<Int>).add(4) // this results to java.lang.UnsupportedOperationException } list is MutableCollection returns true that shows Kotlin Immutable collection objects implements MutableCollection interface but instead of changing items in collection it throws