Options menu with setOnItemClickListener

2

I have a listview , and with setOnItemClickListener and / or setOnItemLongClickListener I delete the registry.

I would like to know how to open a janela (type a modal, which opens the window and dims the background) with opções , eg confirm / cancel.

Would you have to create a new activity and pass the values to it?! And to stay just one little window with the dark background as we see in many apps?

If you have articles, tutorials, etc. you can send that I like to see everyone.

    
asked by anonymous 11.10.2017 / 15:48

1 answer

4

Create a AlertDialog . Ex:

 AlertDialog.Builder builder = new AlertDialog.Builder(SuaClasse.this);
 builder.setTitle("Excluir");
 builder.setMessage("Deseja excluir o registro?");
 builder.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // faz a exclusão
        }
     });
 builder.setNegativeButton("Não", null); //não faz nada
 builder.setIcon(android.R.drawable.ic_dialog_alert);
 builder.show();

The Builder class is responsible for creating and configuring AlertDialogs .

Final example:

    
11.10.2017 / 15:57