itemselect上的导航抽屉

时间:2016-01-14 08:48:01

标签: java android navigation-drawer

Case_history_review.java

 public class Case_history_review extends AppCompatActivity {

private DrawerLayout drawerLayout;
private TextView contentView;
private int navItemId;
private static final String NAV_ITEM_ID = "nav_index";


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


    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("E-care");
    setSupportActionBar(toolbar);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
    view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            Toast.makeText(Case_history_review.this, menuItem.getItemId() + " pressed", Toast.LENGTH_LONG).show();
            Log.d(R.id.nav_1+"", menuItem.getItemId() + " ");
            switch (menuItem.getItemId())
            {


                case R.id.nav_1:

                    break;
                case R.id.nav_2:
                    Intent intent = new Intent();
                    intent.setClass(Case_history_review.this,PatientReport.class);
                    intent .putExtra("name", "Hello B Activity");
                    break;
                case R.id.nav_3:
                    break;
                case R.id.nav_4:
                    break;
                case R.id.nav_5:
                    break;
                case R.id.nav_6:
                    break;

            }
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            return true;
        }
    });

    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.drawer_open , R.string.drawer_close){
        @Override
        public void onDrawerClosed(View drawerView) {
            super .onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super .onDrawerOpened(drawerView);
        }
    };

    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

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

@Override
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.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

private void navigateTo(MenuItem menuItem){

    navItemId = menuItem.getItemId();
    menuItem.setChecked(true);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(NAV_ITEM_ID, navItemId);
}

}

01-14 02:16:05.618 13054-13054/com.example.yuen.e_carei D/2131493023: 2131493024 
01-14 02:16:05.677 13054-13089/com.example.yuen.e_carei W/EGL_emulation: eglSurfaceAttrib not implemented
01-14 02:16:05.677 13054-13089/com.example.yuen.e_carei W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf3e82160, error=EGL_SUCCESS
01-14 02:16:05.703 13054-13089/com.example.yuen.e_carei V/RenderScript: 0xf3da9a00 Launching thread(s), CPUs 2
01-14 02:16:07.733 13054-13054/com.example.yuen.e_carei D/2131493023: 2131493023 

我检查了开关盒。它在logcat中显示了相同的数据,但我无法想到另一个类。点击按钮后我保持不变。请给我一些帮助来解决这个问题。谢谢你

1 个答案:

答案 0 :(得分:0)

你想开始另一项活动吗? 如果是,请致电

stratActivity(intent);