Reputation: 17
FYI I'm starting to learn Kotlin & have previous experience with Python and PyQT.
Goal is to have a for loop iterate a certain amount of times based on user input. Each iteration of the for loop should bring up an alert dialog that saves the text input to ArrayList.
Currently, an alert dialog shows asking for the site name. After entering the name and tapping 'Ok' an alert dialog shows asking for the amount of buildings at the site. That input gets saved as an integer used as the for loop limit. This is when the app crashes. The alert dialog asking for the site name never shows. Any suggestions?
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()
}
}
No errors show when compiling. Just warning about some parameters never being used.
Upvotes: 0
Views: 305