Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's certainly possible, the only thing you need to do is to generate your own IDs. The IDs may be anything but they must not conflict with the aapt IDs (the ones in R) and must not be negative.</p> <p>The following example demonstrates this with a set of fixed IDs:</p> <pre><code>public class MainActivity extends Activity { private final int ID_TABLE = 0xA; private final int ID_ROW1 = 0xB; private final int ID_ROW2 = 0xC; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout ll = (LinearLayout) findViewById(R.id.root); TableLayout tl = new TableLayout(this); tl.setId(ID_TABLE); TableRow tr1 = new TableRow(this); tr1.setId(ID_ROW1); TableRow tr2 = new TableRow(this); tr2.setId(ID_ROW2); tl.addView(tr1); tl.addView(tr2); ll.addView(tl); MyFragment frag1 = new MyFragment(); MyFragment frag2 = new MyFragment(); MyFragment frag3 = new MyFragment(); MyFragment frag4 = new MyFragment(); getFragmentManager().beginTransaction() .add(ID_ROW1, frag1, "cell1_1") .add(ID_ROW1, frag2, "cell1_2") .add(ID_ROW2, frag3, "cell2_1") .add(ID_ROW2, frag4, "cell2_2") .commit(); getFragmentManager().executePendingTransactions(); } } </code></pre> <p>In order to switch to a different layout, you can remove the fragments and add them elsewhere.<br> Let me know how it goes.</p> <p>EDIT: to clarify, Views and ViewGroups don't need to be instantiated once and then kept for the lifetime of the Activity. Just make sure any fragments are either removed or detached before removing their associated view. Also, if you create and remove views outside of onCreate you should make sure it can be restored by using onSaveInstanceState and repeating the process in onCreate. Read the <a href="http://d.android.com/reference/android/app/Activity.html" rel="nofollow">diagram here</a> and the paragraph about <a href="http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges" rel="nofollow">configuration changes</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload