My activity is not showing the menu button, in none of the cases Administrator or Attendant

0

public class PrincipalActivity extends AppCompatActivity {

private FirebaseAuth autenticacao;
private DatabaseReference referenciaFireBase;
private TextView tipoUsuario;
private Usuario usuario;
private String tipoUsuarioEmail;
private Menu menu1;
private Menu menu2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    tipoUsuario =  findViewById(R.id.txtTipoUsuario);
    autenticacao = FirebaseAuth.getInstance();

    referenciaFireBase = FirebaseDatabase.getInstance().getReference();


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    menu.clear();
    this.menu1 = menu;
    //recebendo o email do usuario logado no momento
    String email = autenticacao.getCurrentUser().getEmail().toString();

    referenciaFireBase.child("usuario").orderByChild("email").equalTo(email.toString()).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()){
                tipoUsuarioEmail = postSnapshot.child("tipoUsuario").getValue().toString();

                tipoUsuario.setText(tipoUsuarioEmail);

                menu1.clear();

                if (tipoUsuarioEmail.equals("Administrador")){
                    getMenuInflater().inflate(R.menu.menu_admin, menu1);
                }else if (tipoUsuarioEmail.equals("Atendente")){
                    getMenuInflater().inflate(R.menu.menu_atend, menu1);
                }
            }

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


    return false;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.action_add_usario) {
        abrirTelaCadastroUsuario();
    } else if (id == R.id.action_sair_admin) {
        deslogarUsuario();
    }else if (id == R.id.action_sair_atend) {
        deslogarUsuario();
    }

    return super.onOptionsItemSelected(item);
}

private void abrirTelaCadastroUsuario() {
    Intent intent = new Intent(PrincipalActivity.this, CadastroUsuarioActivity.class);
    startActivity(intent);
}

private void deslogarUsuario() {
    autenticacao.signOut();

    Intent intent = new Intent(PrincipalActivity.this, MainActivity.class);
    startActivity(intent);
    finish();

}

}

    
asked by anonymous 10.07.2018 / 20:29

0 answers