1

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 2

1

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

Sign up to request clarification or add additional context in comments.

8 Comments

so i would have my xml with all my other stuff in, then i could inflate that layout with my TableLayout xml layout?
Right, define another layout xml file with your TableLayout, then inflate that file and add the view programmatically.
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?
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.
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
|
0

In your xml layout, let's say you want to add the TableLayout inside a RelativeLayout with an id of relativeLayout1.

To add it, you would do the following code:

TableLayout table = new TableLAyout();

// Code to add rows and views to the table

R.findViewById("relativeLayout1").add(table);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.