首页 > 解决方案 > 如何在此对话框中开始另一个活动?

问题描述

当我单击“确定”按钮时,我想进入“PickSeatActivity”。这是我尝试过的,但是 android studio 用红线强调了“意图”对象

        val builder = AlertDialog.Builder(this.requireActivity())

         // Dialog will have "Make a selection" as the title
         builder.setMessage("Details successfully captured.Do you wish to proceed and book your seat?")
             .setPositiveButton("OK") { dialogInterface: DialogInterface, i: Int ->
                 val intent = Intent(PickSeatActivity::class.java)
                 startActivity(intent)


             }
             // A "Cancel" button that does nothing
             .setNegativeButton("Cancel") { dialog, id ->
                 // Nothing happening here either
             }

标签: androidkotlindialogandroid-alertdialog

解决方案


替换你的代码

val intent = Intent(PickSeatActivity::class.java)
             startActivity(intent)

val intent = Intent(this.requireActivity(), PickSeatActivity::class.java)
             startActivity(intent)

推荐阅读