ExpandableListView и NavigationDrawer
У меня довольно странная проблема. Моя логика проста, мое приложение используетNavigationDrawer
для навигации по основному приложению, и из-за сложности доступных опций, я хочу использоватьExpandableListViev
вкладывать некоторые элементы навигации.
Проблема? Просто: список предметов загружается в ящик; однако они нет, чтобы показать детям.
Вопрос Есть ли причина, по которой это нет расширить? Должен ли я использовать другой виджет пользовательского интерфейса для этого?
Некоторые заметки: Я добавил тот же код в другую активность, но вместо размещенияExpandableListViev
на ящик, я добавил его на простойLinearLayout
как единственный элемент, и этохорошо работает там.
Мой макет для деятельности:
Код активности:
private DrawerLayout mDrawerLayout;
private ExpandableListView mDrawerList;
private ExpandableDrawerAdapter mDrawerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ExpandableListView) findViewById(R.id.left_drawer);
// set up the drawer's list view with items and click listener
mDrawerAdapter = new ExpandableDrawerAdapter(this);
mDrawerList.setAdapter(mDrawerAdapter);
mDrawerList.setOnGroupClickListener(new DrawerGroupClickListener());
mDrawerList.setOnChildClickListener(new DrawerChildClickListener());
}
И, наконец, очень простой адаптер:
public class ExpandableDrawerAdapter extends BaseExpandableListAdapter {
private static final int CAMPAIGNS = 0;
private static final int CONVERSIONS = 1;
private static final int MYACCOUNT = 2;
private LayoutInflater mInflater;
private String[] mainNavItems, campaignNavItems, myAccountNavItems;
public ExpandableDrawerAdapter (Activity context) {
this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mainNavItems = context.getResources().getStringArray(R.array.main_nav_items);
this.campaignNavItems = context.getResources().getStringArray(R.array.campaigns_nav_items);
this.myAccountNavItems = context.getResources().getStringArray(R.array.my_account_nav_items);
}
public Object getChild(int groupPosition, int childPosition) {
switch (groupPosition) {
case CAMPAIGNS:
return campaignNavItems[childPosition];
case MYACCOUNT:
return myAccountNavItems[childPosition];
default:
return "";
}
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.drawer_child_list_item, null);
}
TextView childText = (TextView) convertView.findViewById(R.id.drawer_child_list_item_text);
childText.setText((String) getChild(groupPosition, childPosition));
return convertView;
}
public int getChildrenCount(int groupPosition) {
switch (groupPosition) {
case CAMPAIGNS:
Constants.logMessage("Children for group position: " + groupPosition + " are: " + campaignNavItems.length);
return campaignNavItems.length;
case CONVERSIONS:
Constants.logMessage("Children for group position: " + groupPosition + " are: " + 0);
return 0;
case MYACCOUNT:
Constants.logMessage("Children for group position: " + groupPosition + " are: " + myAccountNavItems.length);
return myAccountNavItems.length;
default:
return 0;
}
}
public Object getGroup(int groupPosition) {
return mainNavItems[groupPosition];
}
public int getGroupCount() {
return mainNavItems.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.drawer_list_item,
null);
}
TextView groupText = (TextView) convertView.findViewById(R.id.drawer_list_item_text);
groupText.setText((String) getGroup(groupPosition));
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}