views:

16

answers:

1

Hi guys,

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

A: 

Do you have any ideas why that doesn't work?

Because you do not have a widget whose ID is @+id/category1_menu_layout presently defined in your activity.

Maybe there is another ways of doing this?

Use a ListView. Or use an ExpandableListView. Or inflate the categories using getLayoutInflater(). Or create the categories in Java code.

CommonsWare