2014-09-30 151 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(); 
相關問題