kotlin

【18】kotlin object

六眼飞鱼酱① 提交于 2020-07-24 22:29:35
只有一个实例的类,就是一个单例 不能自定义构造方法 可以实现接口、继承父类 本质上就是单例模式最基本的实现 kt 用object修饰的类 就相是一个单例模式 object MusicPlayer {} 等价于java的这段代码 package com.yzdzy.kotlin.chapter4.objects; public class MuicPlayerJava { public static MuicPlayerJava INSTANCE=new MuicPlayerJava(); public MuicPlayerJava(){} } 可以在编译器双击shift后。输入show k 打开右边的对应编译的java代码中看到类似于上面的java代码参考 -------------------------- objects.kt代码参考 package com.yzdzy.kotlin.chapter4.objects class Driver interface OnExternalDriverMountListerner { fun onMount(driver: Driver) fun onUnmount(driver: Driver) } abstract class Player object MusicPlayer : Player()

2020年7月中国编程语言排行榜

浪尽此生 提交于 2020-07-24 00:35:00
编程语言比例 排名 编程语言 平均工资 中位数 最低 最高 人头 百分比 1 rust 20027 17500 5357 45000 460 0.11% 2 scala 19342 17500 7000 45000 2849 0.68% 3 python 18345 16000 6000 45000 32897 7.80% 4 go 18256 16000 6856 40000 27035 6.41% 5 matlab 18207 17500 7000 37500 5798 1.38% 6 lua 18061 16500 6388 37500 3944 0.94% 7 r 17834 16000 6000 40000 3129 0.74% 8 julia 17667 18929 9000 25000 12 0.00% 9 swift 17053 15000 7000 37500 2770 0.66% 10 perl 16854 15000 5408 37500 2576 0.61% 11 ruby 16196 15000 5250 37500 1373 0.33% 12 kotlin 16106 15000 7000 33050 1217 0.29% 13 haskell 15308 15000 11500 31425 26 0.01% 14 cpp 15282 12500

How to handle retrofit socket timeout for uploading files in android kotlin?

Deadly 提交于 2020-07-23 08:37:18
问题 var client = OkHttpClient() val builder = OkHttpClient.Builder() val gson = GsonBuilder() .setLenient() .create() builder.addInterceptor(AddCookiesInterceptor(mcontext)) builder.addInterceptor(ReceivedCookiesInterceptor(mcontext)) builder.callTimeout(100,TimeUnit.SECONDS) client = builder.build() retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory

How to handle retrofit socket timeout for uploading files in android kotlin?

强颜欢笑 提交于 2020-07-23 08:36:11
问题 var client = OkHttpClient() val builder = OkHttpClient.Builder() val gson = GsonBuilder() .setLenient() .create() builder.addInterceptor(AddCookiesInterceptor(mcontext)) builder.addInterceptor(ReceivedCookiesInterceptor(mcontext)) builder.callTimeout(100,TimeUnit.SECONDS) client = builder.build() retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory

How to handle retrofit socket timeout for uploading files in android kotlin?

送分小仙女□ 提交于 2020-07-23 08:35:14
问题 var client = OkHttpClient() val builder = OkHttpClient.Builder() val gson = GsonBuilder() .setLenient() .create() builder.addInterceptor(AddCookiesInterceptor(mcontext)) builder.addInterceptor(ReceivedCookiesInterceptor(mcontext)) builder.callTimeout(100,TimeUnit.SECONDS) client = builder.build() retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .addConverterFactory

How to implement endless list with a RecyclerView inside a fragment

心已入冬 提交于 2020-07-23 07:41:07
问题 How do i load more to my RecyclerView list once the user scrolls near the bottom? I have had a look at this stack overflow page but I'm still struggling with trying to implement the code from the Kotlin answer into my code. For better context id like you guys to have a look at my previous question, this shows you how i created my fragment in android studio (it was done by clicking on fragment (list) and choosing an empty fragment). inside of my onCreateView i have this piece of code view.list

How to implement endless list with a RecyclerView inside a fragment

对着背影说爱祢 提交于 2020-07-23 07:40:21
问题 How do i load more to my RecyclerView list once the user scrolls near the bottom? I have had a look at this stack overflow page but I'm still struggling with trying to implement the code from the Kotlin answer into my code. For better context id like you guys to have a look at my previous question, this shows you how i created my fragment in android studio (it was done by clicking on fragment (list) and choosing an empty fragment). inside of my onCreateView i have this piece of code view.list

How to implement endless list with a RecyclerView inside a fragment

你。 提交于 2020-07-23 07:39:06
问题 How do i load more to my RecyclerView list once the user scrolls near the bottom? I have had a look at this stack overflow page but I'm still struggling with trying to implement the code from the Kotlin answer into my code. For better context id like you guys to have a look at my previous question, this shows you how i created my fragment in android studio (it was done by clicking on fragment (list) and choosing an empty fragment). inside of my onCreateView i have this piece of code view.list

transfer bitmap between two activities in Kotlin

三世轮回 提交于 2020-07-23 06:56:10
问题 There are some answers using java in stackoverflow but i am unable to convert it into kotlin code. I am new to kotlin. Please tell me how to transfer bitmap data from one activity to another using Intent 回答1: You need to pass the bitmap as an extra argument to the intent while starting the activity. val intent = new Intent(this, NewActivity::class.java) intent.putExtra("BitmapImage", bitmap) startActivity(intent); and retrieve it as: val bitmap = this.intent?.getParcelableExtra("BitmapImage")

transfer bitmap between two activities in Kotlin

耗尽温柔 提交于 2020-07-23 06:55:31
问题 There are some answers using java in stackoverflow but i am unable to convert it into kotlin code. I am new to kotlin. Please tell me how to transfer bitmap data from one activity to another using Intent 回答1: You need to pass the bitmap as an extra argument to the intent while starting the activity. val intent = new Intent(this, NewActivity::class.java) intent.putExtra("BitmapImage", bitmap) startActivity(intent); and retrieve it as: val bitmap = this.intent?.getParcelableExtra("BitmapImage")