上周在公司做了个分享,转成图片发吧
suspend fun displayMyMultipleChoiceDialog(): MyDialogResult {
lateinit var result: Continuation<MyDialogResult>
AlertDialog.Builder(this)
.setTitle(...string resource...)
.setMessage(...string resource...)
.setPositiveButton(...RETRY string..., { dialogInterface: DialogInterface, _: Int ->
dialogInterface.dismiss()
result.resume(MyDialogResult.RETRY)
})
.setNegativeButton(...CANCEL string..., { dialogInterface: DialogInterface, _: Int ->
dialogInterface.dismiss()
result.resume(MyDialogResult.CANCEL)
})
.setOnCancelListener {
result.resume(MyDialogResult.CANCEL)
}
.create()
.show()
return suspendCoroutine {continuation -> result = continuation}
}
fun myPresenterMethod() {
launchAsync {
when (view.displayMyMultipleChoiceDialog()) {
RETRY -> ...do something...
CANCEL -> ...do something else...
}
}
}
btw最近准备看一下redex~ 希望能尽快出专题