我最近开始在Android中开发我的第一个应用程序。
我目前正在研究我想实现的导航原理,而我正努力使其中的一种实现。
我目前在NavDrawer中有一个ExpandableListView,它将根据我创建的用于生成菜单的类来创建不同类型的片段:
MenuModel
public class MenuModel {
public String menuName, defContent, ContentType;
public boolean hasChildren, isGroup, isContent;
public MenuModel(String menuName, boolean isGroup, boolean hasChildren, String defContent, boolean isContent, String ContentType) {
this.menuName = menuName;
this.defContent = defContent;
this.isGroup = isGroup;
this.hasChildren = hasChildren;
this.isContent = isContent;
this.ContentType = ContentType;
}
我的ExpandableListView的OnChildClick
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Fragment fragment = null;
Class fragmentClass = null;
if (childList.get(headerList.get(groupPosition)) != null) {
MenuModel model = childList.get(headerList.get(groupPosition)).get(childPosition);
if (model.isContent) {
switch(model.ContentType) {
case "Youtube": {
fragment = YouTubeFragment.newInstance(model.defContent);
break;
}
case "Web": {
fragment = WebFragment.newInstance(model.defContent);
break;
}
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
onBackPressed();
}
}
最终,会有更多的内容类型。
我还设法构建了一个单独的ViewPager,该ViewPager始终未链接到我的ExpandableListView或MenuModel。
我想要做的是让OnChildClick创建一个ViewPager,其中包含选定Child父级的所有子级的片段,同时还将MenuModel中的逻辑应用于ViewPager中的每个片段。
它还应该根据expandablelistview中的子位置在正确的位置打开ViewPager。我很确定我可以在Google搜寻时看到一些有关这一点的信息。
但是我不知道从哪里开始,我尝试了谷歌搜索,但是我只能找到关于ViewPagers和ExpandableListView的单独教程-我找不到关于链接两者的任何信息。
任何人都可以提供示例和指导,或者指向我吗?
抱歉,如果我在这篇文章中的任何时候都没有使用正确的术语,我只是从昨天开始学习。
谢谢, 瑞安。