Home > other >  Create a pop-up list to fill a textView
Create a pop-up list to fill a textView

Time:09-16

I'm new to android studio and the layouts, I'm trying to recreate something that I don't even know how it's called, which makes difficult to find answers. I have re-create in the image below the thing I'm trying to accomplish :

My layout idea

What I would like to do is 1 : To have a textView asking to choose something. 2 : When we click on it a popup appear displaying different things to choose, we could scroll through those things if the list is long. 3 : Then when clicking on the thing we want our choice is displayed in the textView.

After some research the closest thing that I've found are "drop-down menu", but it does not really match what I'm aiming for (displayed below text instead of popup, no way to scroll inside if the list of things is long, at least for the tutorial I've found).

CodePudding user response:

You can use AlertDialog and setItems to pass array string.

val builder = AlertDialog.Builder(this)
builder.setTitle(R.string.pick_color)
        .setItems(R.array.colors_array,
                  DialogInterface.OnClickListener { dialog, which ->
                            // The 'which' argument contains the index position
                            // of the selected item
         })
builder.create()

Where R.array.colors_array is your array, you can define it in XML or programmatically.

Please check this

  • Related