문제

I have a simple android app which is creating dynamically list and adding to FragmentManager. the list class is referring to a layout item which is included a merge layout. tho whole app is using SherlockFragmentActivity.

Now I wanted to add a permanent footer to the existing FragmentManager without disturbing the current functionality.

This footer should be available all the pages.

Can anybody please help me to do this?

here is the on java code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getSupportFragmentManager();
    // Create the list fragment and add it to sole content.

    if (fm.findFragmentById(android.R.id.content) == null) {
        ClockListFragment list = new ClockListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit(); 

        //adding the list to the content
    }
}

here ClockListFragment is the class which is adding the content:

public static class ClockListFragment extends SherlockListFragment implements
LoaderManager.LoaderCallbacks<Cursor>, PauseSource {

    variablesdeclarations.......

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setEmptyText(getText(R.string.no_clock_defined));
        setHasOptionsMenu(true);

        mAdapter = new ClockCursorAdapter(getActivity(), R.layout.world_clock_item, null, this);
        setListAdapter(mAdapter);

        setListShown(false);

        ListView listView = getListView();
        setupCabOld(listView);
        registerPreferenceChanged();

        if (savedInstanceState != null) {
            // Restore contextual action bar state
            CharSequence cab = savedInstanceState.getCharSequence(CAB);
            if (cab != null) {
                mMode = getSherlockActivity().startActionMode(new ModeCallback());
                mMode.setTitle(cab);
                mMode.invalidate();
            }
        }

        getLoaderManager().initLoader(0, null, this);
        Clocks.updateOrder(getActivity());
        updateWeather(false);
    }

    ........ other codes
}
도움이 되었습니까?

해결책

I have a base layout xml that my activity(s) use:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/content_pane"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_above="@+id/footer_layout">

     </FrameLayout>

     <include layout="@layout/footer"/>
</RelativeLayout>

Then you can add/replace your fragments to @+id/content_pane (framlayout). And of course you need a footer layout.

To use in your example:

  1. Add setContentView(R.layout.base); to your activity onCreate-method.
  2. Change fm.beginTransaction().add(android.R.id.content, list).commit(); to fm.beginTransaction().add(R.id.content_pane, list).commit();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top