2016-11-14 30 views
1

我想实现一个Drawermenu在我的Android应用程序与选项:安卓:扩大子菜单中DrawerMenu

  1. 简介
  2. 设置
  3. 信息

对于Drawermenu的实现有很多教程,都很清晰,但是我找不到任何关于在我的Reddit应用程序中添加与此类似的子菜单的任何内容:

With click on "My Subscriptions" the List of my Subscriptions expands

随着点击“我的订阅”我的订阅列表展开。

难道这真的很难实现吗? 任何想法或建议表示赞赏

我有抽屉设置是这样的:

布局XML:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- The main content view --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <!-- The navigation drawer --> 
    <ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="left|start" 
     android:background="#ffeeeeee"/> 
</android.support.v4.widget.DrawerLayout> 

MainActivity:

package com.example.simon.drawtest; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class MainActivity extends Activity { 
    private ListView mDrawerList; 
    private ArrayAdapter<String> mAdapter; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     mDrawerList = (ListView) findViewById(R.id.left_drawer); 
     addDrawerItems(); 
    } 
    private void addDrawerItems() { 
     String[] osArray = {"Profile", "Settings", "Info"}; 
     mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray); 
     mDrawerList.setAdapter(mAdapter); 
    } 
} 

谢谢伙计们!

回答

2

您需要将您的ListView替换为ExpandableListView。这是一个很好的tutorial开始。

+0

虽然这可能在理论上回答这个问题,但[这将是更可取的](// meta.stackoverflow.com/q/8259)在这里包含答案的基本部分,并提供供参考的链接。 –

+0

谢谢!这为我解决了这个问题。我所要做的就是遵循教程,然后更改我的activity_main.xml,以便它实际上是一个抽屉,并且可以从左侧拉出。 即使我同意@ cricket_007的说法,这个人在几分钟内就解决了它,所以我会将其标记为正确答案!再次感谢! – Simon