kotlin 扩展函数

https://www.kotlincn.net/docs/reference/extensions.html

扩展函数在android中的应用

fun AppCompatActivity.replaceFragmentInActivity(fragment: Fragment, @IdRes frameId: Int) {
supportFragmentManager.transact {
replace(frameId, fragment)
}
} fun AppCompatActivity.addFragmentToActivity(fragment: Fragment, tag: String) {
supportFragmentManager.transact {
add(fragment, tag)
}
} private inline fun FragmentManager.transact(action: FragmentTransaction.() -> Unit) {
beginTransaction().apply {
action()
}.commit()
}

kotlin扩展函数的更多相关文章

  1. 利用Kotlin扩展函数实现任意View的点击处理(点击效果和防止快速点击)

    利用Kotlin扩展函数实现View的点击处理(点击效果和防止快速点击) kotlin经典写法: view?.setOnClickListener { //实现 } 项目实践证明,这种写法存在问题 例 ...

  2. 用Kotlin开发Android应用(III):扩展函数和默认值

    这是关于Kotlin的第三篇. 原文标题:Kotlin for Android (III): Extension functions and default values 原文链接:http://an ...

  3. Kotlin的扩展函数:扩展Android框架(KAD 08)

    作者:Antonio Leiva 时间:Jan 11, 2017 原文链接:https://antonioleiva.com/extension-functions-kotlin/ 扩展函数是Kotl ...

  4. 【编程语言】Kotlin之扩展函数

    简介: 平时Android开发中会使用各种各样的工具类函数,大部分工具类都是对原有对象的一种扩展,例如: public static void startActivity(Activity act, ...

  5. Spring Webflux: Kotlin DSL [片断]

    原文链接:https://dzone.com/articles/spring-webflux-kotlin-dsl-snippets 作者:Biju Kunjummen 译者:Jackie Tang ...

  6. Kotlin入门(22)适配器的简单优化

    列表视图 为实现各种排列组合类的视图(包括但不限于Spinner.ListView.GridView等等),Android提供了五花八门的适配器用于组装某个规格的数据,常见的适配器有:数组适配器Arr ...

  7. 你还在把Java当成Android官方开发语言吗?Kotlin了解一下!

    导语:2017年Google IO大会宣布使用Kotlin作为Android的官方开发语言,相比较与典型的面相对象的JAVA语言,Kotlin作为一种新式的函数式编程语言,也有人称之为Android平 ...

  8. 初识Kotlin之函数

    本章通过介绍Kotlin的基本函数,默认参数函数,参数不定长函数,尾递归函数,高阶函数,Lamdba表达式.来对Kotlin函数做进一步了解.将上一篇的Kotlin变量的知识得以运用.Kotlin变量 ...

  9. Kotlin扩展深入解析及注意事项和可见性

    可见性[Visibility]: 在Java中的可见性有public.protected.private.default四种,而在Kotlin中也有四种:public.protected.privat ...

随机推荐

  1. 一个符号冲突导致的core分析

    问题描述: 修改跟踪程序(Trace)支持IPV6时,发现程序启动后正常,但是客户端一旦下发查询条件进行跟踪,Trace程序就直接coredump! (gdb) bt # 0x00007f7dab9e ...

  2. Android 图片文字单位 px、dp、sp区别

    文章来源:http://www.cnblogs.com/bjzhanghao/archive/2012/11/06/2757300.html px:像素,一个像素点,1px代表屏幕上一个物理的像素点: ...

  3. InfluxDB数据备份和恢复方法,支持本地和远程备份

    本文属于<InfluxDB系列教程>文章系列,该系列共包括以下 17 部分: InfluxDB学习之InfluxDB的基本概念 InfluxDB学习之InfluxDB的基本操作 Influ ...

  4. 【bzoj3173】[Tjoi2013]最长上升子序列 Treap

    题目描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? 输入 第一行一个整数N,表示我们要 ...

  5. 内存检测工具valgrind

    valgrind --tool=memcheck --leak-check=full --error-limit=no  --trace-children=yes  ./server valgrind ...

  6. Codeforces 934.D A Determined Cleanup

    D. A Determined Cleanup time limit per test 1 second memory limit per test 256 megabytes input stand ...

  7. tornado 坑集合

    1.没有自己的session管理 2.path入参要用括号圈起来,才能获取到 3.接收post参数 data = json.loads(self.request.body)ddd = data[&qu ...

  8. 【Error】Python:UnicodeDecodeError: ‘XXX' codec can't decode bytes in position... 解决方法

    错误信息: UnicodeDecodeError: ‘XXX' codec can't decode bytes in position 2-5: illegal multibyte sequence ...

  9. Cisco IPC Emergency Responder Error

    Upon startup of the newer Cisco IP Communicator clients (especially on Windows Vista/7), sometimes y ...

  10. readbook:自己设计mvc框架,java类似struts2的实现

    如果你不能简单说清楚,就是你还没有完全明白.——爱因斯坦 need things: 1.操作xml文档 dom4j 等开源类库 2. dtd的验证 等知识储备 * n到n次     ? 0到1次    ...