Created
December 13, 2017 19:37
-
-
Save abdul-rehman-2050/3d224886ff584434cbe983ce221f573d to your computer and use it in GitHub Desktop.
creating alert dialog with ArrayList<String>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Refference
https://stackoverflow.com/questions/15762905/how-can-i-display-a-list-view-in-an-android-alert-dialog