• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you work with an App Bar to clear and repopulate the GUI when a menu item is clicked?

 
Eric Sweeten
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Android Studio, but not to Java. I understand how to make an App Bar. What I don't understand is how to lay out GUI components on the screen dependent on which menu item is selected in that app bar. Do I need to make multiple activities for this? Is there some way I can make a container and add/remove the container depending on which menu item is selected? This seems like something very simple yet I cannot find a tutorial on it. I find tutorials on how to make the app bar and how to listen when the menu items are clicked, but nothing past that.

Great thanks to any ideas.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make different Activities, which would likely work well. Or, create and place the items programmatically, by instantiating the objects and adding them to the current layout.
 
Eric Sweeten
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Tkatch wrote:You can make different Activities, which would likely work well. Or, create and place the items programmatically, by instantiating the objects and adding them to the current layout.


I tried to do that but it kept throwing errors. Do I create my own layout and add it to the phone background, then add things to the layout? If so, how do I go about doing that?
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not need to create a layout, unless one does not exist. You do, however, need a reference to the layout, which is done like any other object, except it'll be in R.layouts, rather than R.id. Once you have the layout as a variable, layout.add() should do the trick. That is, instantiate an object, and add the object to the layout.

If you are receiving errors, please show your code. I'm sure we can work it out from there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic