我有一个带有10个选项的导航抽屉 选项#5 shoudl有另外7种可扩展/可折叠的选项(如子菜单)
如何创建“可折叠导航项”,如here所述?
答案 0 :(得分:17)
以下是一个示例应用程序:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.drawer_group_item,parent,false);
}
((TextView) convertView).setText(groupItem.get(groupPosition));
convertView.setTag(groupItem.get(groupPosition));
return convertView;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
tempChild = (ArrayList<String>) children.get(groupPosition);
TextView text = null;
if (convertView == null)
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.drawer_submenu_item,parent,false);
}
text = (TextView) convertView;
text.setText(tempChild.get(childPosition));
convertView.setTag(tempChild.get(childPosition));
return convertView;
}
您必须在布局文件夹中创建新的xml文件(提示:创建两个,一个用于组视图,另一个用于子菜单)
毕竟您的侧面导航必须如下所示: