Skip to content

Instantly share code, notes, and snippets.

@abdul-rehman-2050
Created December 13, 2017 19:37
Show Gist options
  • Save abdul-rehman-2050/3d224886ff584434cbe983ce221f573d to your computer and use it in GitHub Desktop.
Save abdul-rehman-2050/3d224886ff584434cbe983ce221f573d to your computer and use it in GitHub Desktop.
creating alert dialog with ArrayList<String>
fun showDialogWithList(arrayList: ArrayList<String>){
val builderSingle = AlertDialog.Builder(this@MainActivity)
builderSingle.setIcon(R.mipmap.ic_launcher_foreground)
builderSingle.setTitle("Select One Name:-")
builderSingle.setNegativeButton("cancel") { dialog, which -> dialog.dismiss() }
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList)
builderSingle.setAdapter(adapter) { dialog, which ->
val strName = adapter.getItem(which)
val builderInner = AlertDialog.Builder(this@MainActivity)
builderInner.setMessage(strName)
builderInner.setTitle("Your Selected Item is")
builderInner.setPositiveButton("Ok") { dialog, which -> dialog.dismiss() }
builderInner.show()
}
builderSingle.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment