官术网_书友最值得收藏!

How it works...

Thanks to treating OnClickListener as a function, we were able to implement it in the clean and concise form of a lambda expression. The lambda's body will globally be invoked whenever the user clicks the button. In our case, once the button is clicked, it will be hidden away.

Lambda expressions are one of the most essential functional features of the language and are used extensively in the standard library components. They can be seen as an abbreviated form of a function or a functional interface implementation. Lambdas help to organize code correctly and reduce a lot of boilerplate code. The syntax of a lambda expression can be seen as a block of code placed between { } symbols. Lambda expressions can have function arguments defined explicitly, for example:

val myFunction: (View) -> Unit = { view ->
view.visibility = View.INVISIBLE
}

For the sake of brevity, the explicit parameter can be omitted. However, we can still access it using it modifier:

val myFunction: (View) -> Unit = { 
it.visibility = View.INVISIBLE
}

主站蜘蛛池模板: 布拖县| 北安市| 庄河市| 景德镇市| 湾仔区| 临桂县| 麦盖提县| 蕲春县| 周口市| 双峰县| 怀集县| 秦皇岛市| 城固县| 张家川| 东乌珠穆沁旗| 拉孜县| 界首市| 贵南县| 大渡口区| 商水县| 乡城县| 手机| 昌乐县| 元朗区| 西乌珠穆沁旗| 平阴县| 思南县| 明水县| 灵丘县| 塔河县| 鲁甸县| 田东县| 长春市| 游戏| 聂荣县| 通河县| 革吉县| 内江市| 衡阳县| 阳江市| 崇阳县|