在Android中使用数组资源的自定义AlertDialog

时间:2018-09-24 09:21:45

标签: android kotlin alertdialog

我想使用数组资源创建自定义AlertDialog。 我有这种类型的arrays.xml资源

<array name="bug_type">
    <item>
            {"id":\"1\", "type":\"Wrong Question\"}
    </item>
    <item>
        {"id":\"2\", "type":\"Wrong Answer\"}
    </item>
</array>

我尝试创建具有自定义布局的自定义AlertDialog。 这是我的代码

 try {
                        // AlertDialog for TimeOut of Exam
                        val mBuilder = AlertDialog.Builder(this@ExamActivity)
                        val mView = layoutInflater.inflate(R.layout.show_result_popup, null)
                        val mResult = mView.findViewById(R.id.resultBtn) as Button
                        val textView = mView.findViewById(R.id.examFinishPopupText) as TextView
                        mBuilder.setView(mView)
                        val dialog = mBuilder.create()
                        dialog.setCanceledOnTouchOutside(false)
                        dialog.setCancelable(false)
                        dialog.show()
                        textView.text = getString(R.string.finishExamtime)
                        mResult.setOnClickListener {
                            isPaused = true
                            val intent = Intent(applicationContext, ResultActivity::class.java)
                            startActivity(intent)
                        }

                    } catch (e: Exception) {
                        Log.e("catch", "${e}")
                    }
                }

0 个答案:

没有答案