kotlin

Gson deserialize Array of Integers in kotlin

馋奶兔 提交于 2020-08-10 19:42:05
问题 Normally, when I deserialize a json-String I use something like this: val result = gson.fromJson<myObject>(json, object : TypeToken<myObject>() {}.type) But now I want to deserialize a simple List of Int and I cannot build an object for that. The json-String is extremely simple and looks like this: [1,35,37,255] and I would like to save it into a List but val result = gson.fromJson<List<Int>>(json, object : TypeToken<List<Int>>() {}.type) does not work because there is no object. How should I

How to find a child Fragment with Navigation Architecture components

本秂侑毒 提交于 2020-08-10 19:36:57
问题 After learning basics about new architecture components, I decided to apply this knowledge and work a demo project. In this project I have been working with google map. In my navHost fragment, one of the fragment shows google map this way <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment"></fragment> from the code I have been trying to get this fragment class, the related code

How to find a child Fragment with Navigation Architecture components

柔情痞子 提交于 2020-08-10 19:35:33
问题 After learning basics about new architecture components, I decided to apply this knowledge and work a demo project. In this project I have been working with google map. In my navHost fragment, one of the fragment shows google map this way <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment"></fragment> from the code I have been trying to get this fragment class, the related code

Spring not null validation throwing HttpMessageNotReadableException instead of MethodArgumentNotValidException in kotlin

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-10 18:26:29
问题 I'm making and simple application in Kotlin using Spring but I'm having a problem with the validation. I have this entity class: @Entity @Table(name = "category") data class Category( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long?, @field:NotNull @field:NotEmpty val name: String) And my controller function like this: @PostMapping @ResponseStatus(HttpStatus.CREATED) fun create(@Valid @RequestBody category: Category): ResponseEntity<Category> create have some code, but it

Changing MainActivity entry while integrating React native and android application

有些话、适合烂在心里 提交于 2020-08-10 12:57:57
问题 I am are working on POC to integrate native android app with React Native. After following all steps in react native official docs for integration, I had an error MainActivity.java does not exist. Not sure but I guess its cosreact-native run-android works through MainActivity.java. But in native android app we dun have any such activity file. From AndroidManifest.xml it looks this is the first activity: <application android:name=".core.exampleApplication" so to customize to this activity file

Unable to refresh recyclerView with pagination

谁都会走 提交于 2020-08-10 12:25:25
问题 I have a RecyclerView that gets filled with paginated data. I need to be able to refresh it via SwipeRefreshLayout , but so far, I am unable to do so. I have tried plenty references that does similar to this, but without any success. Also, for letting you guys know, When I do refresh, the data gets retrieved correctly, but it is not being displayed on the recyclerView... Also, when I move from that destination to another via Navigation and then, I hit back, it gets updated. I am not sure what

Unable to refresh recyclerView with pagination

点点圈 提交于 2020-08-10 12:23:47
问题 I have a RecyclerView that gets filled with paginated data. I need to be able to refresh it via SwipeRefreshLayout , but so far, I am unable to do so. I have tried plenty references that does similar to this, but without any success. Also, for letting you guys know, When I do refresh, the data gets retrieved correctly, but it is not being displayed on the recyclerView... Also, when I move from that destination to another via Navigation and then, I hit back, it gets updated. I am not sure what

Kotlin与java8的SAM转换对比

杀马特。学长 韩版系。学妹 提交于 2020-08-10 09:10:53
什么是sam 转换 Single Abstract Method 实际上这是java8中提出的概念,你就把他理解为是 一个方法的接口 的就可以了 看一下我们每天都在使用的线程池 ExecutorService executorService= Executors.newScheduledThreadPool(3 ); executorService.execute( new Runnable() { @Override public void run() { System.out.println( "hello world" ); } }); 用下面的java8中的lambda 来写 也是可以的。 executorService.execute(()->System.out.println("hello world")); 所以说 这两种写法是 等价 的。 但是这里要强调的是 java中的lambda是没有类型的,所以他必须需要一个接口来接受他。 kotlin中的sam val executorService: ExecutorService = Executors.newScheduledThreadPool(3 ) // kotlin中的 匿名内部类的标准写法 executorService.submit(object :Runnable{ override fun run()

Kotlin make constructor of data class accept both List and MutableList but store a mutable instance of them

拜拜、爱过 提交于 2020-08-10 05:04:51
问题 I want to make a data class which can accept both list and mutable-list and if the list is instance of MutableList then directly make it a property else if it is a List then convert it into a MutableList and then store it. data class SidebarCategory(val title: String, val groups: MutableList<SidebarGroup>) { constructor(title: String, groups: List<SidebarGroup>) : this(title, if (groups is MutableList<SidebarGroup>) groups else groups.toMutableList()) } In the above code Platform declaration

Kotlin make constructor of data class accept both List and MutableList but store a mutable instance of them

匆匆过客 提交于 2020-08-10 05:04:29
问题 I want to make a data class which can accept both list and mutable-list and if the list is instance of MutableList then directly make it a property else if it is a List then convert it into a MutableList and then store it. data class SidebarCategory(val title: String, val groups: MutableList<SidebarGroup>) { constructor(title: String, groups: List<SidebarGroup>) : this(title, if (groups is MutableList<SidebarGroup>) groups else groups.toMutableList()) } In the above code Platform declaration