Bottomnavigationview does not work on first click

Asked

Viewed 46 times

0

I’m having a problem in my forward menu, it does not work when I click the first time, it is necessary to click twice to perform the action

bottomNavigationView.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
@Override
public void onNavigationItemReselected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menuAvancar:
            if (camposObrigatoriosWS()) {

                DatabaseHelper db = new DatabaseHelper(getApplicationContext());
                ClienteDao clienteDao = new ClienteDao();
                clienteDao.buscarUltimoID(db);
                //Verifica se quer continuar cadasto de pacote ou somente cliente
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(CadastrarClienteActivity.this);
                LayoutInflater inflater = getLayoutInflater();
                View dialogView = inflater.inflate(R.layout.item_dialog_cadastro_cliente, null);
                dialogBuilder.setView(dialogView);

                iniciarComponentesDialog(dialogView);

                dialogBuilder.create().show();

                btnContinuar.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        inserirCliente("N");
                        Intent intent = new Intent(CadastrarClienteActivity.this, EscolherPacoteActivity.class);
                        startActivity(intent);
                    }
                });

                btnCadastrar.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        inserirCliente("S");
                        Intent intent = new Intent(CadastrarClienteActivity.this, CaixaDeEntradaActivity.class);
                        startActivity(intent);
                    }
                });
            } else {
                toastUtil.exibirToastCurtoPrazo(CadastrarClienteActivity.this, "Campos obrigatorios não informado");
            }
            break;

1 answer

3


That’s because you’re wearing the setOnNavigationItemReselectedListener. As the name says, Reselect, is only called when the item is already selected and is again clicked.

For your case, use the setOnNavigationItemSelectedListener.

Browser other questions tagged

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