How to add row which is having multiple column dynamically in android?-Collection of common programming errors

I think you will understand best through an example. Lets simplify things a little bit. Lets say your main layout is this:




It’s a simple TableLayout without any views yet (You could have pre-baked rows in it). Now you want to create TableRows wich you want to add dinamically, and handle it’s subviews separately, right? You could create your whole TableRow in xml:



    
    

Then the java part. Lets say you want to add 10 of those rows to your TableLayout, and handle each rows button and separately. You can do it like this (You must have access to a Context object):

// get the main TableLayout from xml
TableLayout layout = (TableLayout) findViewById(R.id.main_layout);  

// get a LayoutInflater object. 'this' is the current Activity
LayoutInflater inflater = LayoutInflater.from(this);

for(int i=0; i