Trending Articles       10 Flutter Listview Examples       Flutter Custom Button Example       Flutter Audio Recording       Flutter 2.0 Autocomplete TextField       Current Location Google Maps

How to display Listview inside Dialog in Android | Kotlin Example

How to display Listview inside Dialog in Android application. In this example, we are going to create Dialog with Listview.

Let's get started

Step 1: Create a Project in Android studio

Step 2: Create an Activity and add functionality to show the dialog.

Create Alert Dialog

val builderSingle: AlertDialog.Builder = AlertDialog.Builder(this@MainActivity)


This AlertDialog.Builder object contains a method called setAdapter to show the List of data with Listview.

builderSingle.setAdapter(arrayAdapter, DialogInterface.OnClickListener { dialog, which ->




package com.rrtutors.listviewinsidedialog

import android.content.DialogInterface
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Button

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
       var btn=findViewById<Button>(
        btn.setOnClickListener {

            val builderSingle: AlertDialog.Builder = AlertDialog.Builder(this@MainActivity)
            builderSingle.setTitle("Select One HotSpot:-")

            val arrayAdapter = ArrayAdapter<String>(this@MainActivity, android.R.layout.select_dialog_singlechoice)
            arrayAdapter.add("HotSpot 1")
            arrayAdapter.add("HotSpot 2")
            arrayAdapter.add("HotSpot 3")
            arrayAdapter.add("HotSpot 4")
            arrayAdapter.add("HotSpot 5")
            arrayAdapter.add("HotSpot 6")
            arrayAdapter.add("HotSpot 7")
            arrayAdapter.add("HotSpot 8")
            arrayAdapter.add("HotSpot 9")
            arrayAdapter.add("HotSpot 10")

            builderSingle.setNegativeButton("cancel", DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() })

            builderSingle.setAdapter(arrayAdapter, DialogInterface.OnClickListener { dialog, which ->




Step 3: Now run the application

ListView inside Dialog in Android


Related: Save Image in SQLite Database Android - Kotlin


Author: RRTutors

Flutter Questions

Android Questions