private fun showLegendDialog() {val dialogView = LayoutInflater.from(this).inflate(R.layout.legend_dialog, null)val builder = AlertDialog.Builder(this) .setTitle("Legend") .setView(dialogView) .setPositiveButton("Close") { dialog, _ -> dialog.dismiss() } val dialog = builder.create() dialog.show()val legendLayout: LinearLayout = dialogView.findViewById(R.id.legendLayout)val mapImageLayer = mapView.map?.operationalLayers?.get(0) as? ArcGISMapImageLayer mapImageLayer?.let { CoroutineScope(Dispatchers.Main).launch { for (sublayer in it.mapImageSublayers) {val legenddata = sublayer.fetchLegendInfos()for (legendInfo in legenddata) { // error is here val legendImageView = ImageView(this@MainActivity)val symbol = legendInfo.symbolif (symbol != null) {// Set the symbol directly to the ImageView legendImageView.setImageDrawable(symbol.toDrawable(this@MainActivity)) legendLayout.addView(legendImageView) }val legendName = legendInfo.nameif (legendName.isNotEmpty()) {val legendNameTextView = TextView(this@MainActivity) legendNameTextView.text = legendName legendLayout.addView(legendNameTextView) } } }} }Error is at for (legendInfo in legenddata) Android Studio keeps throwing an error stating the "For-loop range must have an 'iterator()' method"
fetchLegendInfos() is a suspending function and all suspending functions in the ArcGIS Maps SDK for Kotlin return a Result type. In this case the result wraps a List<LegendInfo>.
One way to get the list from the result is to write the following
val legenddata = sublayer.fetchLegendInfos().getOrThrow()
This worked thank you
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.