How to change Activity by clicking on an option in the Alertdialog menu?

Asked

Viewed 548 times

0

I have the following problem, I have a method that is called, when one clicks on a button, AND HOLD, (onLongClickListener) will appear an Alert with several options. 1st Option is Cancel the Table, 2nd View orders, and 3rd Call another Action. It happens, that gives error when I click on the third option, where would be my Intent, calling another Activity.

Obs: Initialization of the other Activity has no error, because I can access it by other buttons using the same method Intent Intent = new Intent();

private AlertDialog opcoes;
CharSequence op[] = new CharSequence[] {"Cancelar Mesa", "Ver Pedidos", "Acrescentar/Alterar Pedido", "Teste"};
private void opcoesMesas(final View v) {
    //Cria o gerador do AlertDialog
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // define o titulo
    builder.setTitle("Escolha a Opção desejada: ");
    //define a mensagem
    //builder.setMessage("Deseja cancelar essa mesa?");
    //define um botão como positivo
    builder.setItems(op, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
                switch(i){
                    case 0:
                        ConfirmacaoDeCancelamento(v);
                        break;
                    case 1:
                        exibindoPedidosDasMesas(v);
                        break;

                    case 2:
                        openPedidos();
                        break;

                    case 3:
                        break;

                    default:
                }


        }
    });
    builder.show();
}


private void openPedidos(){
    startActivity(new Intent(getBaseContext(),pedidos.class));
}

In case 2:, I already tried to put the Intent straight, also can not. And he recognizes that he was clicked on the third option, because I already put a Toat to inform me in case 2, and it worked.

Help me, I just need to call another screen, by clicking on Case 2.

  • Pole the logcat with the error.

1 answer

2


Before I go to the next activity call the method dismiss() dialog and then call the method openPedidos()

  • what you do, what’s the point of this() ?

  • closes the dialog. call it : dialogInterface.Dismiss(); or dialogInterface.getDialog(). Dismiss();

Browser other questions tagged

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