Issue
I have a problem, that i dont know how can i add a textview to a gridlayout. I have an xml:
<TextView
android:id="@+id/textView1"
android:layout_column="2"
android:layout_columnSpan="3"
android:layout_gravity="center_horizontal|top"
android:layout_row="3"
android:layout_rowSpan="2"
android:text="TextView" />
And would like to do this xml code dynamically. How can i do this? I know how to create textview, but i dont know how to add to the gridlayout...
Solution
GridLayout gv = (GridLayout) findViewById(R.id.gridlayout);
TextView tv = new TextView(context);
tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
tv.setText("TextView");
LayoutParams params = new LayoutParams(Set your column and row information as params);
tv.setLayoutParams(params);
gv.addView(tv);
You can't paste the code in and it will need to be tested and changed to fit (it won't just work). But it should give you the general idea.
Answered By - JamieB