如何在navigationbar Android中放置三级expandablelistview

如何在navigationbar Android中放置三级expandablelistview,android,expandablelistview,navigationbar,Android,Expandablelistview,Navigationbar,我想在导航栏中添加3级可扩展列表视图。在每个扩展上都会有子单击。我在导航栏中实现了2级可扩展listview,但3级给我造成了错误。是否有任何第三方库用于此。 如果你的项目中有人这样做,请指导我解决这个问题 我的2级导航可扩展列表代码如下所示 public class MainActivity extends AppCompatActivity { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawe

我想在导航栏中添加3级可扩展列表视图。在每个扩展上都会有子单击。我在导航栏中实现了2级可扩展listview,但3级给我造成了错误。是否有任何第三方库用于此。 如果你的项目中有人这样做,请指导我解决这个问题

我的2级导航可扩展列表代码如下所示

public class MainActivity extends AppCompatActivity {

private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private String mActivityTitle;
private String[] items;

private ExpandableListView mExpandableListView;
private ExpandableListAdapter mExpandableListAdapter;
private List<String> mExpandableListTitle;
private NavigationManager mNavigationManager;

private Map<String, List<String>> mExpandableListData;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mActivityTitle = getTitle().toString();

    mExpandableListView = (ExpandableListView) findViewById(R.id.navList);
    mNavigationManager = FragmentNavigationManager.obtain(this);

    initItems();

    LayoutInflater inflater = getLayoutInflater();
    View listHeaderView = inflater.inflate(R.layout.nav_header, null, false);
    mExpandableListView.addHeaderView(listHeaderView);

    mExpandableListData = ExpandableListDataSource.getData(this);
    mExpandableListTitle = new ArrayList(mExpandableListData.keySet());

    addDrawerItems();
    setupDrawer();

    if (savedInstanceState == null) {
        selectFirstItemAsDefault();
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
}

private void selectFirstItemAsDefault() {
    if (mNavigationManager != null) {
        String firstActionMovie = getResources().getStringArray(R.array.actionFilms)[0];
        mNavigationManager.showFragmentAction(firstActionMovie);
        getSupportActionBar().setTitle(firstActionMovie);
    }
}

private void initItems() {
    items = getResources().getStringArray(R.array.film_genre);
}

private void addDrawerItems() {
    mExpandableListAdapter = new CustomExpandableListAdapter(this, mExpandableListTitle, mExpandableListData);
    mExpandableListView.setAdapter(mExpandableListAdapter);
    mExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            getSupportActionBar().setTitle(mExpandableListTitle.get(groupPosition).toString());
        }
    });

    mExpandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
        @Override
        public void onGroupCollapse(int groupPosition) {
            getSupportActionBar().setTitle(R.string.film_genres);
        }
    });

    mExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {
            String selectedItem = ((List) (mExpandableListData.get(mExpandableListTitle.get(groupPosition))))
                .get(childPosition).toString();
            getSupportActionBar().setTitle(selectedItem);

            if (items[0].equals(mExpandableListTitle.get(groupPosition))) {
                mNavigationManager.showFragmentAction(selectedItem);
            } else if (items[1].equals(mExpandableListTitle.get(groupPosition))) {
                mNavigationManager.showFragmentComedy(selectedItem);
            } else if (items[2].equals(mExpandableListTitle.get(groupPosition))) {
                mNavigationManager.showFragmentDrama(selectedItem);
            } else if (items[3].equals(mExpandableListTitle.get(groupPosition))) {
                mNavigationManager.showFragmentMusical(selectedItem);
            } else if (items[4].equals(mExpandableListTitle.get(groupPosition))) {
                mNavigationManager.showFragmentThriller(selectedItem);
            } else {
                throw new IllegalArgumentException("Not supported fragment type");
            }

            mDrawerLayout.closeDrawer(GravityCompat.START);
            return false;
        }
    });
}
public类MainActivity扩展了AppCompatActivity{
私人抽屉布局mDrawerLayout;
私有操作bardrawertoggle mDrawerToggle;
私有字符串mactivitytle;
私有字符串[]项;
私有可扩展列表视图mExpandableListView;
私有可扩展列表适配器mExpandableListAdapter;
私有列表mExpandableListTitle;
私人导航经理mNavigationManager;
私有地图mExpandableListData;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
mActivityTitle=getTitle().toString();
mExpandableListView=(ExpandableListView)findViewById(R.id.navList);
mNavigationManager=FragmentNavigationManager.get(此);
initItems();
LayoutInflater充气机=getLayoutInflater();
视图listHeaderView=充气机。充气(R.layout.nav_标题,空,假);
mExpandableListView.addHeaderView(listHeaderView);
mExpandableListData=ExpandableListDataSource.getData(这个);
mExpandableListTitle=新的ArrayList(mExpandableListData.keySet());
addDrawerItems();
setupDrawer();
如果(savedInstanceState==null){
选择FirstItemasDefault();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
私有void selectFirstItemAsDefault(){
if(mNavigationManager!=null){
String firstActionMovie=getResources().getStringArray(R.array.ActionMovies)[0];
mNavigationManager.showFragmentAction(firstActionMovie);
getSupportActionBar().setTitle(firstActionMovie);
}
}
私有项目(){
items=getResources().getStringArray(R.array.film_流派);
}
私有void addDrawerItems(){
mExpandableListAdapter=新的CustomExpandableListAdapter(此,mExpandableListTitle,mExpandableListData);
setAdapter(mExpandableListAdapter);
mExpandableListView.setOnGroupExpandListener(新的ExpandableListView.OnGroupExpandListener(){
@凌驾
public void onGroupExpand(int groupPosition){
getSupportActionBar().setTitle(mExpandableListTitle.get(groupPosition.toString());
}
});
mExpandableListView.setOnGroupCollapseListener(新的ExpandableListView.OnGroupCollapseListener(){
@凌驾
公共void-onGroupCollapse(int-groupPosition){
getSupportActionBar().setTitle(R.string.film_体裁);
}
});
mExpandableListView.setOnChildClickListener(新的ExpandableListView.OnChildClickListener(){
@凌驾
公共布尔onChildClick(ExpandableListView父视图,视图v,
int groupPosition、int childPosition、long id){
字符串selectedItem=((列表)(mExpandableListData.get(mExpandableListTitle.get(groupPosition)))
.get(childPosition.toString();
getSupportActionBar().setTitle(selectedItem);
if(items[0].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentAction(selectedItem);
}else if(items[1].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentComicle(selectedItem);
}else if(items[2].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragment戏剧性(selectedItem);
}else if(items[3].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentMusic(selectedItem);
}else if(items[4].equals(mExpandableListTitle.get(groupPosition))){
mNavigationManager.showFragmentThriller(selectedItem);
}否则{
抛出新的IllegalArgumentException(“不支持的片段类型”);
}
mDrawerLayout.closeDrawer(重力compat.START);
返回false;
}
});
}
自定义可扩展适配器

public class CustomExpandableListAdapter extends BaseExpandableListAdapter {

private Context mContext;
private List<String> mExpandableListTitle;
private Map<String, List<String>> mExpandableListDetail;
private LayoutInflater mLayoutInflater;
private Map<String, List<String>> mExpandableSecondListData;
public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,
                                   Map<String, List<String>> expandableListDetail) {
    mContext = context;
    mExpandableListTitle = expandableListTitle;
    mExpandableListDetail = expandableListDetail;
    mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    System.out.println("expandable"+mExpandableListTitle+mExpandableListDetail);






}

@Override
public Object getChild(int listPosition, int expandedListPosition) {
    return mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
        .get(expandedListPosition);
}

@Override
public long getChildId(int listPosition, int expandedListPosition) {

    return expandedListPosition;
}

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

    final String expandedListText = (String) getChild(listPosition, expandedListPosition);
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(R.layout.list_item, null);
    }
    TextView expandedListTextView = (TextView) convertView
        .findViewById(R.id.expandedListItem);
    expandedListTextView.setText(expandedListText);
    CustomExpListView SecondLevelexplv = new CustomExpListView(mContext);
    SecondLevelexplv.setAdapter(new SecondExpandableListAdapter(mContext));
    SecondLevelexplv.setGroupIndicator(null);

    return convertView;
}

@Override
public int getChildrenCount(int listPosition) {
    return mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
        .size();
}

@Override
public Object getGroup(int listPosition) {
    return mExpandableListTitle.get(listPosition);
}

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

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

@Override
public View getGroupView(int listPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {
    String listTitle = (String) getGroup(listPosition);
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(R.layout.list_group, null);
    }
    final TextView listTitleTextView = (TextView) convertView
        .findViewById(R.id.listTitle);
    listTitleTextView.setTypeface(null, Typeface.BOLD);
    listTitleTextView.setText(listTitle);

    return convertView;
}

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

@Override
public boolean isChildSelectable(int listPosition, int expandedListPosition) {
    return true;
}
公共类CustomExpandableListAdapter扩展了BaseExpandableListAdapter{
私有上下文;
私有列表mExpandableListTitle;
私有地图mExpandableListDetail;
私人停车场平面布置;
私有地图mExpandableSecondListData;
公共CustomExpandableListAdapter(上下文、列表expandableListTitle、,
地图可展开列表(详细信息){
mContext=上下文;
mExpandableListTitle=expandableListTitle;
mExpandableListDetail=expandableListDetail;
mLayoutInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
System.out.println(“可扩展”+mExpandableListTitle+mExpandableListDetail);
}
@凌驾
公共对象getChild(int listPosition,int expandedListPosition){
返回mExpandableListDetail.get(mExpandableListTitle.get(listPosition))
.get(expandedListPosition);
}
@凌驾
公共长getChildId(int-listPosition、int-expandedListPosition){
返回expandedListPosition;
}
@凌驾
公共视图getChildView(int listPosition,最终int expandedListPosition,
布尔值isLastChild、视图转换视图、视图组父级){
最终字符串expandedListText=(字符串)getChild(listPosition,expandedListPosition);
if(convertView==null){
convertView=MLAYOUTINGER.充气(R.layout.list_项,空);
}
TextView expandedListTextView=(TextView)convertView
.findViewById(R.id.expandedListItem);
扩展列表