Android studio导航抽屉 - 在导航右侧添加箭头图标

时间:2016-06-13 05:28:16

标签: android

请帮帮我。

如何在导航栏右侧添加箭头图标?

示例:

家居GT;

CATEGORY>

我的帐户>

这是我的代码。

JSONObject jsonObj = new JSONObject(CATEGORIESJSON);
categories = jsonObj.getJSONArray(CATEGORIES_RESULTS);

listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<Category>>();

// Adding group data
listDataHeader.add("HOME");
listDataHeader.add("CATEGORY");
listDataHeader.add("MY ACCOUNT");
listDataHeader.add("REFER A FRIEND");
listDataHeader.add("ABOUT");
listDataHeader.add("PRIVACY POLICY");
listDataHeader.add("SHIPPING TERMS");
listDataHeader.add("SHOPPING GUIDE");
listDataHeader.add("CONTACT US");
if(customersid.matches("10865")){
    listDataHeader.add("LOGIN");
}else{
    listDataHeader.add("LOGOUT");
}

List<Category> CATEGORY = new ArrayList<Category>();
for(int i=0;i<categories.length();i++){
    JSONObject c = categories.getJSONObject(i);
    Category category = new Category();
    category.name = c.getString(CATEGORIES_NAME);
    category.id = c.getString(CATEGORIES_ID);
    category.image2 = c.getString(CATEGORIES_IMAGE2);

    CATEGORY.add(category);
}

listDataChild.put(listDataHeader.get(1), CATEGORY); // Header, Child data

这是我的ExpandableListAdapter代码

package com.example.administrator.mosbeau;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;


/**
 * Created by Administrator on 9/21/2015.
 */

@SuppressWarnings("deprecation")

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<Category>> _listDataChild;

    public ExpandableListAdapter(Context context, List<String> listDataHeader,
                                 HashMap<String, List<Category>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Category getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final Category childCategory = (Category) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        txtListChild.setText(childCategory.name);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        ExpandableListView mExpandableListView = (ExpandableListView) parent;
        mExpandableListView.expandGroup(1);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}

请帮帮我。

感谢,

1 个答案:

答案 0 :(得分:1)

您知道为xml布局使用'include'标记吗?

我想我有一些参考资料让你这样做..看到这个link,它有一个很好的解释