怎样使用item跳转页面?

想要使用item跳转页面
图片说明

比如让item的id为nav_camera的跳转到main.xml,方法怎么写?希望有大佬告知

public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    //HOME页面右上角menu菜单
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        MenuInflater inflater_item = getMenuInflater();
        inflater_item.inflate(R.menu.main, null);
        switch (item.getItemId()){
            case R.id.add_contact:
                Toast.makeText(this, "123", Toast.LENGTH_SHORT).show();
                break;
            case R.id.add_whitelist:
                Toast.makeText(this, "456", Toast.LENGTH_SHORT).show();
                break;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

看见ifelse就头疼。你的安卓基础不行,不是main.xml而是MainActivity,xml只是相当于配置文件而已,最终还是解析到class里面。
startActivity(new Intent(this,MainActivity.class))

大于2个的状态判断,建议用switch 建议去菜鸟教程 那里有专门的课程 照着来一遍