Hiiii there, I have an xml layout and when a button is clicked I need to add a TableLayout view to that xml layout. I know how to do this with simple stuff like text views but tables would seem to be a lot harder to define programmatically, Im not quite sure what inflating is but is that what I should be using? Thanks.
2 Answers
You can define the layout in an xml file and then simply inflate that layout using the LayoutInflater. This will give you a View (in your case this will be a TableLayout), then add this view and you are done.
Reference: LayoutInflater
8 Comments
Andy Lobel
so i would have my xml with all my other stuff in, then i could inflate that layout with my TableLayout xml layout?
aromero
Right, define another layout xml file with your TableLayout, then inflate that file and add the view programmatically.
Andy Lobel
any chance you could tell us what inflate exactly means LOL does it mean getting all the stuff from the xml so you can use it in the code?
aromero
Inflate means take the xml definition and create the objects for the views with their configuration. Think of it as when you call "setContentView" in your Activity. I've added a reference to the method you need to use.
Andy Lobel
kk thanks D: i think i get it nearly lol i just read the inflate arguments which i need and confused the shit outa myself
|