Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Fragments in One Activity
    primarykey
    data
    text
    <p>The issue of many fragments in one activity has been covered here before, but I cannot seem to find a solution for my positioning problem.</p> <p>I want a horizontal scroll bar on top of the screen and under it a custom ListFragment. The code I am posting below puts up the scroll bar and then the ListFragment overwrites it. When I try to modify the hosting FrameLayout to have two FrameLayouts I get runtime errors. </p> <p>Simply, How can I position the listFragment under the scrollbar?</p> <pre><code> public class GoogleNewsMainActivity extends FragmentActivity{ public static Context c; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); c=this; setContentView(R.layout.activity_fragment); /* FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); if (fragment == null) { Scroll_Menu_Fragment scrollFragment = new Scroll_Menu_Fragment(); fm.beginTransaction() .add(R.id.fragmentContainer, scrollFragment) .commit(); GoogleNewsMainFragment f = new GoogleNewsMainFragment(); fm.beginTransaction() .add(R.id.fragmentContainer, f) .commit(); } */ } } </code></pre> <p>Here is the scroll bar fragment:</p> <pre><code> public class Scroll_Menu_Fragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub return inflater.inflate(R.layout.scrollbar_fragment, container, false); } @Override public void onPause() { // TODO Auto-generated method stub super.onPause(); } } </code></pre> <p>This is the ListFragment</p> <pre><code> public class GoogleNewsMainFragment extends ListFragment implements LoaderCallbacks&lt;Cursor&gt; { private static final String COLUMN_ID = "id"; public final static String NEWSFROMSERVICE = "NEWSFROMSERVICE"; static ImageView thumbnail; static String mSectionSelected; private NewsCursor mCursor; private ListView lv; private NewsCursorAdapter adapter; public static final String ID = "id"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); setHasOptionsMenu(true); mSectionSelected = ""; // until they select one getLoaderManager().initLoader(0, null, this); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_google_news_main, container, false); getActivity().setTitle(R.string.news_list_title); return v; } </code></pre> <p>And finally the hosting layout</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragmentContainer" android:baselineAligned="false" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;fragment android:id="@+id/scrollFragment" android:layout_width="fill_parent" android:layout_weight="10" android:layout_height="wrap_content" android:layout_marginTop="10dp" class="com.gilchrist.android.googlenews.Scroll_Menu_Fragment" &gt;&lt;/fragment&gt; &lt;fragment android:id="@+id/listFragment" android:layout_width="fill_parent" android:layout_weight="90" android:layout_height="wrap_content" android:layout_marginTop="10dp" class="com.gilchrist.android.googlenews.GoogleNewsMainFragment" &gt;&lt;/fragment&gt; &lt;/LinearLayout&gt; </code></pre>
    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.
    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