I would like to know how to create a Dialog
containing a ListView
following the example image below.
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