内部类方式是最
private val handler = Handler()
private var count = 0;
inner private class Counter:Runnable{
override fun run(){
count++
tv_result.text = "当前计数值为:$count"
handler.postDelayed(this,1000)
}
}
handler.post(Counter()
匿名内部类
private val counter = object:Runnable{
override fun run(){
count++
tv_result.text = "当前计数值为:$count"
handler.postDelayed(this,1000)
}
}
handler.post(counter)
匿名函数
private val counter = Runnable{
count++
tv_result.text ="当前计数值为:$count"
}
hander.post(counter)
匿名实例
handler.post(Runnable{
count++
tv_result.text = "当前计数值为:$count"
})
匿名实例精简
handler.post{
count+
tv_result.text = "当前计算值为:count"
},1000)