如何添加子项在导航抽屉 [英] How to add subitems in a Navigation Drawer

查看:185
本文介绍了如何添加子项在导航抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的抽屉式导航栏中添加子项,但我不能,因为我不知道逻辑思路来执行它,我尝试过的一些例子,但我能够只显示项目。

I want to add subitems in my navigation drawer but i am not able to execute it because i have no idea about the logic , i have tried some examples but i am able to display only the items.

我曾尝试以下code:

i have tried the following code :

package com.example.demo_data1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class NavDrawer extends Activity {
   String[] menu;
   DrawerLayout dLayout;
   ListView dList;
   ArrayAdapter<String> adapter;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third_page);
    menu = new String[]{"Home","Android","Windows","Linux","Raspberry Pi","WordPress","Videos","Contact Us"};
      dLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
      dList = (ListView) findViewById(R.id.drawerList);
      adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menu);
      dList.setAdapter(adapter);
      dList.setSelector(android.R.color.holo_blue_dark);
      dList.setOnItemClickListener(new OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
      dLayout.closeDrawers();
      Bundle args = new Bundle();
      args.putString("Menu", menu[position]);
      Intent i = new Intent(NavDrawer.this, NavDrawer.class);
      switch(position){
      case 0:
         i = new Intent(NavDrawer.this, MainActivity.class);
         break;
      case 1:
         i = new Intent(NavDrawer.this, Retrieve.class);
         break;
  }
  i.putExtra(null, args);
  startActivity(i);
    }        
      });
  } 
 }

以下是XML布局:

Below is the xml layout:

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

<FrameLayout 
    android:id="@+id/mainContent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></FrameLayout>

<ListView android:id="@+id/drawerList"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#fff"></ListView>

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

我只想子项添加到其各自的项目和子项目应显示其母公司的右侧。

I just want to add subitems to its respective item and the subitems should display on the right side of its parent.

所以,请任何人都可以帮我这米有点新的机器人,

So please anyone can help me with this m a bit new to android,

感谢和问候。

推荐答案

您可以添加视图在XML中的抽屉里。试试这个:

You can add views to drawer in the xml. Try this:


<!-- Main layout -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/app_background"
    android:orientation="vertical" >

    <!-- Place your main screen items here -->
    <TextView
            android:id="@+id/tvText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Main" />
</LinearLayout>

<!-- Slider menu -->

<LinearLayout
    android:id="@+id/menuDrawer"
    android:layout_width="290dp"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:background="@color/app_background"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btButton1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button2" />

        <Button
            android:id="@+id/btButton2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Button2" />
    </LinearLayout>

    <ExpandableListView
        android:id="@+id/elvItems"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

这篇关于如何添加子项在导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆