How to get MenuItem position in the listener using the new NavigationView

后端 未结 5 1237
攒了一身酷
攒了一身酷 2020-12-19 02:44

The topic says it all. How should I go about retrieving the item position on the onClick listener using NavigationView? Also, why is there no getHeader method? Lastly I am d

5条回答
  •  甜味超标
    2020-12-19 03:29

    In my case, i use

    first test whit this..

    Log.d(TAG, navigationView.getMenu().getItem(0).isChecked());
    Log.d(TAG, navigationView.getMenu().getItem(1).isChecked());
    Log.d(TAG, navigationView.getMenu().getItem(2).isChecked());
    

    next this...

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            if(navigationView.getMenu().getItem(0).isChecked()) {
                cerrarSesion();
            }else {
                navigationView.getMenu().getItem(0).setChecked(true);
                seleccionarItem(navigationView.getMenu().getItem(0));
            }
        }
        return false;
    }
    

提交回复
热议问题