I am trying to figure out how to load different groupviews dynamically.
I am creating application that will have menu with 4 categories and each category will have several sub-menu items. I have created four LinearLayouts with sub-menu buttons inside (they are separate xml files).
Now I want to display appropriate sub-menu in my main view every time the category is changed.
So far I have:
HorizontalScrollView sView = (HorizontalScrollView)findViewById(R.id.CustomScrollView);
LinearLayout ll = (LinearLayout)findViewById(R.id.category1_menu_layout);
sView.removeAllViews();
sView.addView(ll);
However this doesn’t work because the ll for some reason is null(category1_menu_layout is the id of the LinearLayout inside the category1_menu.xml)
Do you have any ideas why that doesn’t work? Maybe there is another ways of doing this?
Thanks
Because you do not have a widget whose ID is
@+id/category1_menu_layoutpresently defined in your activity.Use a
ListView. Or use anExpandableListView. Or inflate the categories usinggetLayoutInflater(). Or create the categories in Java code.