哪些代码被误用,可点击菜单项不起作用

时间:2019-04-30 20:27:29

标签: java android xml

我一直在尝试使菜单项看起来可点击,但我不确定。但是我确信它不会按照我的计划进行

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    int id;
    id = item.getItemId();
    if(id == R.id.fndclss){
        Intent fndclss;
        fndclss = new Intent(MainActivity.this,ongoingtask.class);
        MainActivity.this.startActivity(fndclss);
    }
    DrawerLayout menu;
    menu = (DrawerLayout) findViewById(R.id.drawer);
    menu.closeDrawer(GravityCompat.START);
    return false;
}

1 个答案:

答案 0 :(得分:0)

您应尝试使用->

 @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    int id;
    id = item.getItemId();
    if(id == R.id.fndclss){
        Intent fndclss = new Intent(MainActivity.this, ongoingtask.class);
        startActivity(fndclss);
        return true;
    }
    DrawerLayout menu;
    menu = (DrawerLayout) findViewById(R.id.drawer);
    menu.closeDrawer(GravityCompat.START);
    return true;
}