Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramatically add fragments to viewgroup
    primarykey
    data
    text
    <p>basically this is my app(idea) for a tablet landscape orientation: Two Fragments, left fragment is a listfragment populated by a resource.xml file (Got that working).</p> <p>Right fragment is supposed to dynamically change fragment and layout based on which list item the user clicks. Googling so far told me that I need to programatically add and remove fragments to a viewgroup to do that. Is that right?</p> <p>Basically the question is/are:</p> <ol> <li>How do I create the viewgroup and where (Main.java or menufragment.java)?</li> <li>How do I put the dynamic "user clicked ID 3 on the list so add fragment 3 to the viewgroup"</li> <li>What do I add to my main.xml file? got the fragment for the listfragment in there, what to add for the dynamic viewgroup?</li> </ol> <p><strong>EDIT:</strong></p> <p>So this is what my activity looks like: Main.java</p> <pre><code>public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } </code></pre> <p>This is my listfragment MenuFragment.java</p> <pre><code>public class MenuFragment extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.listfragment, container, false); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.listmenu))); } @Override public void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); Main activity = (Main) getActivity(); } } </code></pre> <p>and finally my main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;fragment android:id="@+id/list" android:layout_width="200dp" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_weight="1" class="com.mwerner.fragmentstest.MainMenu" /&gt; &lt;View android:id="@+id/contentview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/list" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The string array i have in my xml file that populates the list is called "listmenu"</p> <p>I'm a beginner. Plaese tell me where i need to put in the code you wrote down?</p> <p>Thanks, Max</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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