2

I have an app that is using tabHost menu and I need to change it, because the menu items is growing and they don't fit in the current menu. My classes are extending FragmentActivity, I want to know if is possible to use Sliding Menu with them or I will need to change all classes to extend Fragment.

Thanks in advance.

jackcar
  • 659
  • 3
  • 13
  • 28

2 Answers2

1

I think in second fragment when you open third fragment if you add transaction in back state like transaction.addToBackStack(null); than remove this line of code

if problem than show your navigation code from second to third fragment

Dedaniya HirenKumar
  • 2,980
  • 2
  • 22
  • 25
  • Sorry, I guess you didn't understand my question, I want to know if it's possible to use Sliding Menu with FragmentActivity instead of Fragment – jackcar Jan 29 '15 at 16:25
1

If you use jfeinstein10/SlidingMenu in your project, you can implement sliding menu in your FragmentActivity, as you want.

step1. new SlidingMenu and attach to your activity.

Refer to How to Integrate this Library into Your Projects:

You can wrap your Activities in a SlidingMenu by constructing it programmatically (

menu = new SlidingMenu(Context context)) and then calling

menu.attachToActivity(Activity activity, SlidingMenu.SLIDING_WINDOW | SlidingMenu.SLIDING_CONTENT).

SLIDING_WINDOW will include the Title/ActionBar in the content section of the SlidingMenu, while SLIDING_CONTENT does not. You can check it out in the example app AttachExample Activity.

step2. Then implement a SampleListFragment which represent your menu, and add to your activity.

define a fragment container layout fragment_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

call menu.setMenu(R.layout.fragment_menu); to add the fragment container view to your activity,

Lastly, add your SampleListFragment to your activity's fragment manager:

    getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.fragmentContainer, new SampleListFragment())
    .commit();

In this way, you got a sliding menu in your fragment activity. That's all.

Weiyi
  • 1,843
  • 2
  • 22
  • 34