Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行函数,直到另一个函数完成_Java_Android_Kotlin - Fatal编程技术网

Java 运行函数,直到另一个函数完成

Java 运行函数,直到另一个函数完成,java,android,kotlin,Java,Android,Kotlin,我想执行一个函数本身n次,这个函数负责显示一个对话框,但目前这个对话框是同时生成的,我想显示这个对话框,一旦它关闭,再次打开下一个对话框,而不是一下子全部打开 有什么建议吗 这是我这个函数的主要代码 private fun onReportNotification(){ showMessageDialog(ConfirmationDialog.DIALOG_REPORT_CREATED, getString(R.string.service_line_popup_push_title),

我想执行一个函数本身n次,这个函数负责显示一个对话框,但目前这个对话框是同时生成的,我想显示这个对话框,一旦它关闭,再次打开下一个对话框,而不是一下子全部打开

有什么建议吗

这是我这个函数的主要代码

private fun onReportNotification(){
    showMessageDialog(ConfirmationDialog.DIALOG_REPORT_CREATED, getString(R.string.service_line_popup_push_title), getString(R.string.service_line_popup_push_body), getString(R.string.login_password_btn2),"")
}

override fun onResume() {
    super.onResume()
    checkForPendingTicketsToEvaluate()
}

private fun checkForPendingTicketsToEvaluate(){
    ServiceLineRepository.getAllReportsNotAualfied(applicationContext, serverClient){
        boolean: Boolean, unQualifiedReports: ArrayList<Entity.ServiceRequestedElement> ->
        if(boolean){
            unQualifiedReports.forEach {
                async {
                    currentId = it.id
                    currentService = it.requestedService
                    onReportNotification()
                }
            }
        } else {

        }
    }
}

谢谢

这是我能想到的,可能不是最好的做法。但我认为这会解决你的问题

首先,将数组大小传递给
onReportNotification()
函数,并将其从循环中移出,如下所示

        if(boolean){
            unQualifiedReports.forEach {
                async {
                    currentId = it.id
                    currentService = it.requestedService
                }
            }
            onReportNotification(unQualifiedReports.size)
        } else {

        }
然后,在
onReportNotification()
函数中添加数组大小参数,并将其传递给
showMessageDialog()
方法

private fun onReportNotification(totalDialogToBeShown: Int){
    showMessageDialog(ConfirmationDialog.DIALOG_REPORT_CREATED, getString(R.string.service_line_popup_push_title), getString(R.string.service_line_popup_push_body), getString(R.string.login_password_btn2),"", totalDialogToBeShown)
}
最后,在
showMessageDialog()
函数中,将其更改为

open fun showMessageDialog(
    dialogType: String,
    title: String,
    body: String,
    acceptBtn: String,
    cancelBtn: String,
    totalDialogToBeShown: Int
) {
    Log.d(TAG, "showErrorDialog started, body=$body")
    val ft = supportFragmentManager.beginTransaction()
    val prev = supportFragmentManager.findFragmentByTag(ConfirmDialog)
    if (prev != null) {
        ft.remove(prev)
    }
    ft.addToBackStack(null)
    val arg = Bundle()
    arg.putString(ConfirmationDialog.DIALOG_TYPE_KEY, dialogType)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_BODY_KEY, body)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_TITLE_KEY, title)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_ACEEPT_BTN, acceptBtn)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_CANCEL_BTN, cancelBtn)
    val newFragment = ConfirmationDialog.newInstance(arg)
    var numberOfShownDialog = 1
    newFragment.onDismiss(object : DialogInterface {
            override fun dismiss() {
                if (numberOfShownDialog < totalDialogToBeShown) {
                    numberOfShownDialog++
                    ft.let { newFragment.show(it, ConfirmDialog) }
                }
            }

            override fun cancel() {}
    })

    try {
        ft.let { newFragment.show(it, ConfirmDialog) }
        Log.d(TAG, "showMessageDialog, showing dialog")
    } catch (e: Exception) {
        e.printStackTrace()
        e.message?.let {
            Log.e(TAG, it)
        }
    }
}
打开有趣的ShowMessage对话框(
dialogType:String,
标题:字符串,
正文:字符串,
acceptBtn:字符串,
取消BTN:字符串,
totalDialogToBeShown:Int
) {
Log.d(标记“对话框已启动,body=$body”)
val ft=supportFragmentManager.beginTransaction()
val prev=supportFragmentManager.findFragmentByTag(确认对话框)
如果(上一个!=null){
英尺移除(上一个)
}
ft.addToBackStack(空)
val arg=Bundle()
arg.putString(ConfirmationDialog.DIALOG\u TYPE\u键,dialogType)
arg.putString(ConfirmationDialog.DIALOG_TEXT_BODY_KEY,BODY)
arg.putString(ConfirmationDialog.DIALOG_TEXT_TITLE_KEY,TITLE)
arg.putString(ConfirmationDialog.DIALOG_TEXT_acept_BTN,acceptBtn)
arg.putString(ConfirmationDialog.DIALOG\u TEXT\u CANCEL\u BTN,cancelBtn)
val newFragment=ConfirmationDialog.newInstance(arg)
var numberOfShownDialog=1
onDismiss(对象:DialogInterface{
重写{
if(numberOfShownDialog

希望这能解决您的问题:)

那么您将在报告通知上循环
多达
不合格报告
?是的,但我想完成当前的不合格报告,从下一个开始,但我不能,所有报告都同时显示非常感谢,我会注意代码,这会很有帮助的,朋友。你能留下一张选票,看看这是否真的有帮助吗?
open fun showMessageDialog(
    dialogType: String,
    title: String,
    body: String,
    acceptBtn: String,
    cancelBtn: String,
    totalDialogToBeShown: Int
) {
    Log.d(TAG, "showErrorDialog started, body=$body")
    val ft = supportFragmentManager.beginTransaction()
    val prev = supportFragmentManager.findFragmentByTag(ConfirmDialog)
    if (prev != null) {
        ft.remove(prev)
    }
    ft.addToBackStack(null)
    val arg = Bundle()
    arg.putString(ConfirmationDialog.DIALOG_TYPE_KEY, dialogType)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_BODY_KEY, body)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_TITLE_KEY, title)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_ACEEPT_BTN, acceptBtn)
    arg.putString(ConfirmationDialog.DIALOG_TEXT_CANCEL_BTN, cancelBtn)
    val newFragment = ConfirmationDialog.newInstance(arg)
    var numberOfShownDialog = 1
    newFragment.onDismiss(object : DialogInterface {
            override fun dismiss() {
                if (numberOfShownDialog < totalDialogToBeShown) {
                    numberOfShownDialog++
                    ft.let { newFragment.show(it, ConfirmDialog) }
                }
            }

            override fun cancel() {}
    })

    try {
        ft.let { newFragment.show(it, ConfirmDialog) }
        Log.d(TAG, "showMessageDialog, showing dialog")
    } catch (e: Exception) {
        e.printStackTrace()
        e.message?.let {
            Log.e(TAG, it)
        }
    }
}