How to do dialog with listview inside?

0

I would like to know how to create a Dialog containing a ListView following the example image below.

    
asked by anonymous 31.03.2016 / 22:14

2 answers

1

A simple way to do this is to use the setItems method of Dialog, from it you arrow your list, and it is automatically loaded into Dialog.

Example:

final CharSequence[] cores = {"Azul", "Preto", "Verde"};
    AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT);
    builder.setTitle("Selecione uma Cor");
    builder.setItems(cores, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int selecionado) {
            Toast.makeText(getActivity(), "Cor Selecionada: " + cores[selecionado],
                    Toast.LENGTH_SHORT).show();
        }
    });
    builder.create().show();

Note: The context would be an instance of your activity, if you are running within an activity, you can use this

    
01.04.2016 / 16:45
0

DialogFragments can work as dialog boxes on Android. They work like "Activity on another Activity" and, seen in your image, it is possible to make a screen like this (presenting a ListView Widget). Take a look at some examples: link link

    
31.03.2016 / 22:30