0

仅供参考,我开始学习 Kotlin 并且之前有使用 Python 和 PyQT 的经验。

目标是让 for 循环根据用户输入迭代一定次数。for 循环的每次迭代都应弹出一个警告对话框,将文本输入保存到 ArrayList。

目前,会显示一个警告对话框,询问站点名称。输入名称并点击“确定”后,会显示一个警报对话框,询问该站点的建筑物数量。该输入被保存为用作 for 循环限制的整数。这是应用程序崩溃的时候。询问站点名称的警报对话框永远不会显示。有什么建议么?

btn_new_site.setOnClickListener { view ->
        //maybe convert this to seperate .kt and import in.
        //change to one builder & inflater & just change parameters?

        //ask for site name
        val site_builder = AlertDialog.Builder(this)
        val site_inflater = layoutInflater
        site_builder.setTitle("Site Name")
        val dialogLayout = site_inflater.inflate(R.layout.ad_site_name, null)
        val site_name  = dialogLayout.findViewById<EditText>(R.id.site_name)
        site_builder.setView(dialogLayout)
        site_builder.setPositiveButton("OK") { dialogInterface, i ->
            sites.add(site_name.text.toString())
            //ask for amount of buildings at site
            val amt_building_builder = AlertDialog.Builder(this)
            val amt_building_inflater = layoutInflater
            amt_building_builder.setTitle("How many buildings?")
            val dialogLayout = amt_building_inflater.inflate(R.layout.ad_site_amt_buildings, null)
            val site_amt_buildings  = dialogLayout.findViewById<EditText>(R.id.site_amt_buildings)
            amt_building_builder.setView(dialogLayout)
            amt_building_builder.setPositiveButton("OK") { dialogInterface, i ->
                val amtBuildings = site_amt_buildings.text.toString()
                val building_amt = amtBuildings.toInt()

                //ask for building names
                val building_name_builder = AlertDialog.Builder(this)
                val buiding_name_inflater = layoutInflater
                building_name_builder.setTitle("Building Name")
                val dialogLayout = buiding_name_inflater.inflate(R.layout.ad_building_name, null)
                val building_name  = dialogLayout.findViewById<EditText>(R.id.building_name)
                building_name_builder.setView(dialogLayout)
                building_name_builder.setPositiveButton("OK") { dialogInterface, i ->
                    //add to list of buildings for x site here
                }

                //ask for building names here
                for ( buildings in 1..building_amt) building_name_builder.show()
            }
            amt_building_builder.show()
        }

        site_builder.show()

    }


}

编译时不显示错误。只是警告一些从未使用过的参数。

4

0 回答 0