Options menu with setOnItemClickListener

Asked

Viewed 60 times

0

I have a listview, and with setOnItemClickListener and/or setOnItemLongClickListener do the deletion from the record.

I’d like to know how to open a janela (like a modal, which opens the window and blurs the background) with opções, for example: confirm / cancel.

It would have to create a new Activity and pass the values on to her ?! And to stay only a little window with the "dark" background as we see in various apps ?

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

1 answer

2


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 class Builder is responsible for the creation and configuration of AlertDialogs.

Final example:

inserir a descrição da imagem aqui

  • I don’t need to pass any value then !? It would be because it runs within the method !?

  • That, just utilize it within your deletion method, the only thing you will need to delete is the index of the clicked item. You may have to declare the index of the clicked item as final to be able to access it within the Onclicklistener of your Alertdialog, but this depends on its implementation

  • 1

    It worked just right, just a little bit missing from the part: AlertDialog.Builder builder = new AlertDialog.Builder(Main.this); Thank you Zulian ! Hug !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.