2014-09-30 123 views
0

在我的抽屉中选择列表视图项目时遇到问题。我想要实现的是,当我点击该项目时。它应该开启一项新的活动。但抽屉仍然存在。在我的情况下,它作为新窗口打开。这是我的代码:DrawerLayout:在不关闭抽屉的情况下打开新活动

drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 

     @Override 
     public void onItemClick(AdapterView<?> parent, 
           View view, int position, long id) { 
      String sel = (String)parent.getItemAtPosition(position); 
      textSelection.setText(sel); 

      selectItem(position); 
     }}); 

public void selectItem(int position) { 
    Intent intent; 
    switch (position) { 
     case 1: { 
      Intent j = new Intent(jav_mainform.this, jav_joform.class); 
      startActivity(j); 
      break; 
     } 
     default: { 
      Intent i = new Intent(jav_mainform.this, jav_joform.class); 
      startActivity(i); 
      break; 
     } 
    } 

} 
+0

使用fragment.It将保持在同一page.As您正在使用活动的打开新的一页 – 2014-09-30 05:57:03

+0

你有什么例子@yuvaツ? – 2014-09-30 06:03:39

+0

检查它 - http://javatechig.com/android/navigation-drawer-android-example,https://github.com/thecodepath/android_guides/wiki/Fragment-Navigation-Drawer – 2014-09-30 06:07:03

回答

0

这是DrawerLayout的标准行为。开始活动后,您需要自己隐藏抽屉。

mYourDrawerLayout.closeDrawers();