2017-07-14 159 views
-3

我已經創建了基本導航菜單抽屜。我想要做的是改變導航菜單佈局,當我點擊一個選項。 例如:我的菜單有男士,女士,兒童。當我點擊男人,我想加載另一個列表在同一個導航抽屜與菜單包含牛仔褲,襯衫等點擊更改導航抽屜菜單

我已經在一個ListView中創建了兩個列表,但我無法充氣列表中點擊第一個菜單的導航抽屜。 我已經檢查谷歌和Stackoverflow,但似乎沒有答案。

任何幫助,將不勝感激。謝謝。

+0

使用「易損列表視圖」在抽屜中製作子菜單。 –

+0

@VishalChauhan我知道,但那不是我正在尋找的。我想通過改變菜單來改變導航菜單。 –

回答

0

正如您在評論中所說的完全改變導航菜單,請勿直接在抽屜佈局中創建ListView或導航視圖。

將導航菜單作爲抽屜佈局中的片段並在片段佈局xml中創建列表視圖。然後,您可以輕鬆地將一個片段(包含菜單和子菜單列表)替換爲另一個片段。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/main_layout" 
android:background="#ffffff"> 

//main content view 
<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- The drawer is given a fixed width in dp and extends the full height of 
    the container. --> 
<fragment android:id="@+id/navigation_drawer" 
    android:layout_width="200dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:name="Your's Base menu list fragment" 
    tools:layout="@layout/drawer_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

希望這會對你有幫助。