Android Tablelayout Trouble, Adding Views
Solution 1:
Here's the developer page for the View constructors:
https://developer.android.com/reference/android/view/View.html#View%28android.content.Context%29
The second and third parameters for a View are used if you want this view to have certain attributes or styles set upon the creation of that view.
It looks like you actually want your variable leader
to be inflated. This will take a layout defined in xml and assign it to dynamically created view. You said that your leaderLayout is a LinearLayout, so it would look something like this.
//Initialize the layout inflator, do this once and use it to inflate as many views as you wantLayoutInflaterinflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Assign your custom view to the variable leaderLinearLayoutleader= (LinearLayout) inflator.inflate(R.layout.leaderLayout, tr);
The first parameter for inflate is R.layout.nameOfYourXmlFile. The second is the ViewGroup that will be the parent of your inflated View. Once this is done, you can use findViewById
on leader to get the child views in your Xml file, add more children dynamically, and add it as a child of your TableRow.
Here's the developer page for LayoutInflator, in case you're curious about other usages of the inflate
method.
http://developer.android.com/reference/android/view/LayoutInflater.html
Post a Comment for "Android Tablelayout Trouble, Adding Views"