Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Take a look at these Fragment topics:</p> <ul> <li><a href="http://developer.android.com/guide/topics/fundamentals/fragments.html#Adding">Programmatically add the fragment to an existing ViewGroup</a></li> <li><a href="http://developer.android.com/guide/topics/fundamentals/fragments.html#CommunicatingWithActivity">Communicating with the Activity</a></li> </ul> <p>Essentially you'll want to have the <em>left</em> fragment tell the parent Activity which item is selected. Then, the Activity can add/remove the correct fragment in the <em>right</em> pane.</p> <p>Keep in mind that creating/destroying a Fragment is a lot of work for the system. If you can get away with having a single Fragment in the right pane, it will be much more efficient. You can then call methods on that one Fragment instance without building new Fragments.</p> <p>EDIT (example):</p> <p>Your Main Activity implementation with custom method:</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); } /** Called by the left fragment */ public void updateRightPane(long id) { // Get the data with the selected item id // ... // Create a new fragment MyFragment fragment = new MyFragment(data); // Update the layout FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); // The id specified here identifies which ViewGroup to // append the Fragment to. ft.add(R.id.view_group_id, fragment); ft.commit(); } } </code></pre> <p>The <code>onListItemClick</code> implementation for <code>MenuFragment.java</code>:</p> <pre><code>@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // Get the parent Activity Main activity = (Main) getActivity(); // Pass the selected item id to the Activity method // Note: Feel free to update this method to accept additional // arguments (e.g. position). activity.updateRightPane(id); } </code></pre> <p>Finally, your layout file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view_group_id" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;!-- More views here... --&gt; &lt;/RelativeLayout&gt; </code></pre>
    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. 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