列表匹配
发表于|更新于|Code
|浏览量:
列表匹配
1 | calendarEvent?.userList?.let { list -> |
文章作者: Fleming Chen
文章链接: https://flemingme.github.io/2021/11/21/%E4%BB%A3%E7%A0%81/%E5%88%97%E8%A1%A8%E5%8C%B9%E9%85%8D/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Fleming's Blog!
相关推荐
2022-02-08
图片下载及保存
图片下载及保存 确定文件的下载路径,context.getExternalFilesDir(“images”),即app外部存储的files路径,无须动态权限声明 创建URL对象,val url = URL(path),由图片的下载地址创建 通过url.openConnection()打开连接,获取连接对象 连接conn.connect() 获取输入流,val input: InputStream = conn.getInputStream() 创建输出流,准备写入val fos = FileOutputStream(out) 标准io操作,将读到的字节写入到文件中 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253try { val buf = ByteArray(1024) var numRead: Int fos.run { while ((inpu...
2023-11-21
更新当前的选中状态
更新当前的选中状态123456789101112131415161718192021222324252627282930313233private fun updateSelectStatus(curUser: User) { mAdapter.run { var targetPosition = -1 var previousCheckedPosition = -1 // 遍历一次,同时更新状态并记录位置 data.forEachIndexed { index, user -> val wasChecked = user.isChecked val shouldBeChecked = (user.uid == curUser.uid) if (wasChecked != shouldBeChecked) { user.isChecked = shouldBeChecked ...
2022-02-08
Kotlin语法糖
Kotlin语法糖Kotlin 是一种现代编程语言,它引入了许多语法糖和特性,旨在提高代码的简洁性和可读性。以下是一些 Kotlin 中常用的语法糖和特性: 1. 数据类(Data Classes)Kotlin 的数据类自动生成常见的方法,如 equals(), hashCode(), toString(), copy() 等。 1data class User(val name: String, val age: Int) 2. 属性委托(Property Delegates)属性委托允许你将属性的 getter 和 setter 代理给另一个对象。 12345class User { var name: String by Delegates.observable("John Doe") { prop, old, new -> println("$old -> $new") }} 3. 智能转换(Smart Casts)Kotlin 的智能转换允许你在类型...
2021-12-16
VideoView视频播放
VideoView视频播放123456789101112131415val videoView = findViewById<VideoView>(R.id.videoView)val videoUri = Uri.parse("android.resource://$packageName/${R.raw.my_video}")videoView.setVideoURI(videoUri)// 添加播放控制val mediaController = MediaController(this)videoView.mediaController = mediaControllermediaController.setAnchorView(videoView)// 循环播放videoView.setOnCompletionListener { videoView.start()}videoView.start()
2020-02-27
Edittext点击外部区域隐藏软件盘
Edittext点击外部区域隐藏软件盘12345678910111213binding.root.setOnTouchListener { _, event -> if (event.action == MotionEvent.ACTION_DOWN) { val focusedView: View? = activity?.currentFocus if (focusedView is EditText) { // 如果当前焦点在EditText上,并且点击位置不在EditText范围内,隐藏键盘 if (event.x < focusedView.getLeft() || event.x > focusedView.getRight() || event.y < focusedView.getTop() || event.y > focusedView.getBottom()) { ...
2022-02-08
国内镜像地址
国内镜像地址1234567891011121314151617181920buildscript { repositories { maven { url 'https://mirrors.huaweicloud.com/repository/maven/' } maven { url 'https://maven.aliyun.com/repository/public/' } }}allprojects{ repositories { maven { url 'https://mirrors.huaweicloud.com/repository/maven/' } maven { url 'https://maven.aliyun.com/repository/public/' } }}
公告
欢迎来到我的博客,有任何疑问可以随时联系我交流讨论!






