一些多線程的調(diào)用

內(nèi)部類方式是最
private val handler = Handler()
private var count = 0;

inner private class Counter:Runnable{
override fun run(){
count++
tv_result.text = "當(dāng)前計數(shù)值為:$count"
handler.postDelayed(this,1000)
}
}

handler.post(Counter()

匿名內(nèi)部類
private val counter = object:Runnable{
override fun run(){
count++
tv_result.text = "當(dāng)前計數(shù)值為:$count"
handler.postDelayed(this,1000)
}
}

handler.post(counter)

匿名函數(shù)

private val counter = Runnable{
count++
tv_result.text ="當(dāng)前計數(shù)值為:$count"
}
hander.post(counter)

匿名實(shí)例
handler.post(Runnable{
count++
tv_result.text = "當(dāng)前計數(shù)值為:$count"
})

匿名實(shí)例精簡

handler.post{
count+
tv_result.text = "當(dāng)前計算值為:count" } 匿名實(shí)例精簡(多于兩個參數(shù)) handler.postDelayed({ count++ tv_result.text = "當(dāng)前計算值為:count"
},1000)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容