Kotlin
文章平均质量分 63
Kotlin语言编写的知识
HNHuangJingYu
看看我能发几篇文章
展开
-
Kotlin协程使用
文章目录前言一、 协程是什么?二、使用步骤1.引入库2.集成viewMode使用:viewModelScope总结 前言 为了适应Android发展潮流和学习GitHub上大佬们的代码学习Kotlin协程使用 一、 协程是什么? 轻量:您可以在单个线程上运行多个协程,因为协程支持挂起,不会使正在运行协程的线程阻塞。挂起比阻塞节省内存,且支持多个并行操作。 内存泄漏更少:使用结构化并发机制在一个作用域内执行多项操作。 内置取消支持:取消操作会自动在运行中的整个协程层次结构内传播。 二、使用步骤原创 2021-05-11 20:03:59 · 321 阅读 · 0 评论 -
kotlin 协程作用域
GlobalScope: 全局作用域 (不推荐使用) 默认线程为 DefaultDispatcher-worker-2 其中Default、IO线程名字都为-2 MainScope 暂未测试 ViewModelScope : 当 ViewModel 被销毁时它会自动取消协程任务 lifecycleScope : 个人非常喜欢用 需要导库 如下: implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'//lifecycleScop原创 2021-05-11 20:01:14 · 427 阅读 · 0 评论 -
Kotlin_小练习(Lambda)
Thader类 package xx class Trader(val name: String, var city: String) { override fun toString(): String { return "Trader:" + name + " in " + city } } Transaction数据类 package xx class Transaction(val trader: Trader, val year: Int, val valu原创 2020-11-24 00:07:42 · 114 阅读 · 0 评论 -
Kotlin+RecyclerView+SwipeRefreshLayout
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.co原创 2020-11-04 19:33:40 · 176 阅读 · 0 评论 -
Kotlin实现RecyclerView
上代码 import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import kotlinx.andro原创 2020-11-04 19:27:44 · 402 阅读 · 0 评论 -
kotlin实现网络访问并将放入数据类
导入相关依赖 //okhttp3依赖 compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.9.0' //Gson(谷歌官方 Json 库) implementation 'com.google.code.gson:gson:2.8.5' 所用插件:JSON TO Kotlin Class(不会安装自己百度去) 代码块 数据类:(这里是根据插件生成的类体) data class Emp( va原创 2020-11-04 18:11:43 · 262 阅读 · 0 评论