kotlin

OnClickListener is not working inside my adapter class

空扰寡人 提交于 2021-01-28 19:35:40
问题 I looked at many solutions posted online but they couldn't solve my problem. Probably the adapter position is returning -1 but why? java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1 at java.util.ArrayList.get(ArrayList.java:439) at com.firebase.ui.common.BaseObservableSnapshotArray.getSnapshot(BaseObservableSnapshotArray.java:70) at com.example.twitterclone.adapters.MyAdapter$TweetViewHolder.<init>(MyAdapter.kt:36) at com.example.twitterclone.adapters.MyAdapter.onCreateViewHolder

Places API autocomplete problems

为君一笑 提交于 2021-01-28 19:31:31
问题 Hi I'm new to android and am setting up the autocomplete code for the places api. I was following the google dev instructions on their website and ran into a problem that I can't seem to find any answers on. I can't seem to find any info on what i am supposed to put for ID and NAME on the first line. There are no auto complete suggestions that come up and I haven't been able to find any info on it on the official documentation. I believe I have imported everything that I need to as I don't

How to apply Room TypeConverter to a single field of an entity?

青春壹個敷衍的年華 提交于 2021-01-28 19:07:31
问题 I have been trying different solutions for applying a TypeConverter to a single field of a Room database entity but I am getting an error Cannot figure out how to save this field into database. You can consider adding a type converter for it. When I apply the converter to the entity like this: @Entity(tableName = DBKey.calendarDayTable) @TypeConverters(DateStringConverter::class) data class CalendarDay( @PrimaryKey val date: Date ) everything works as expected, but when I apply it to the

Kotlin DSL Unresolved reference on settings.gradle.ktl

空扰寡人 提交于 2021-01-28 14:41:30
问题 I am getting an unresolved reference build error on settings.gradle.kts when I am referencing variables from the buildSrc module. The strange thing is that when I am using the variables from buildSrc, for example to the app level build.gradle.kts, everything works fine. Also the error occurs only when I build/sync and I am not getting that error(red highlights) on the text editor and the navigation to that variable works fine. Attached you find an image with the setup, thanks a lot. Edit:

Wrong image name and type when saving bitmap Android 8

一笑奈何 提交于 2021-01-28 14:41:25
问题 I have a fun that saves bitmap as PNG or JPG (both not working), but seems like using content values not working as expected. File name is incorrect. File type is incorrect. What am I missing ? Works on Android 10, but not working on Android 8 fun Bitmap.save(context: Context) { val contentResolver = context.contentResolver val contentValues = ContentValues().apply { put(MediaStore.MediaColumns.DISPLAY_NAME, "test.png") put(MediaStore.MediaColumns.TITLE, "test") put(MediaStore.MediaColumns

Converting an entire layout to an image/bitmap

和自甴很熟 提交于 2021-01-28 14:40:32
问题 I have been having an issue with this one line of code for a while and I would really apreciate it if any of you have ideaas about it. What I am trying to do is, save a specific layout( in this case a relative layout) as an image when a person hits a button. this action will transfer the image to the next activity. I'm pretty sure the actual act of transfering is not the problem. It's how I'm converting the layout to an image. below is the code with comments: Here is whats on activity1 //

Kotlin multiplatform project

陌路散爱 提交于 2021-01-28 13:39:22
问题 I want to write a common library using Kotin multiplatform that can be used on android and on ios . This library will have dependencies for each platform, for eg: on android I want to add jsoup as a dependency and on ios I want to add swiftsoup For android adding java libraries as dependencies is rather easy, but for ios I could not find a way. The question is: how can I add a swift library as a dependency to this project for ios ? or can somebody point me to a working project as an example?

How to wrap API responses to handle success and error based on Clean Architecture?

十年热恋 提交于 2021-01-28 12:48:51
问题 What is the approach to wrapping responses from the server and then process? The API is returning responses in the following format: SUCCESS: { "data": [], "statusCode": 200, "statusMessage": "Operation success", "success": true } FAILURE: { "errors": [], "statusCode": 500, "statusMessage": "Something went wrong", "success": false } I'm trying to apply Clean Architecture principles to my application and I want to know how can I wrap the responses to better handle errors? 回答1: fillCities()

How to wrap API responses to handle success and error based on Clean Architecture?

故事扮演 提交于 2021-01-28 12:46:16
问题 What is the approach to wrapping responses from the server and then process? The API is returning responses in the following format: SUCCESS: { "data": [], "statusCode": 200, "statusMessage": "Operation success", "success": true } FAILURE: { "errors": [], "statusCode": 500, "statusMessage": "Something went wrong", "success": false } I'm trying to apply Clean Architecture principles to my application and I want to know how can I wrap the responses to better handle errors? 回答1: fillCities()

Parse Json to Primative Array Kotlin

六月ゝ 毕业季﹏ 提交于 2021-01-28 12:32:00
问题 Maybe this is simple, but I'm missing how to do this. I'm using GSON, kotlin, and retrofit Data.json { "array1":[1,2], "array2":[1,2] } DataObject.kt data class DataObject(array1: List<Int>, array2: List<Int>) The the above fails to deserialize the arrays. 回答1: This is a running example: data class DataObject(val array1: List<Int>, val array2: List<Int>) fun main(args: Array<String>) { val json = """{"array1":[1,2],"array2":[1,2]}""" println(Gson().fromJson(json, DataObject::class.java)) /