I have an ActionBarActivity
(which, by the way, extends android.support.v4.app.FragmentActivity
) and I want to add a fragment to topmost. Here is my code:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
NotificationsFragment fragment = new NotificationsFragment();
ft.add(R.id.pager, fragment).commit();
Where:
NotificationsFragment
extendsandroid.support.v4.app.Fragment
R.id.pager
is the id of the root view (which is aandroid.support.v4.view.ViewPager
)
When the code above runs, nothing happens. No exceptions, crashes or any visual changes. Just nothing. I've seen FragmentTransaction not doing anything and there was a suggestion there telling to use replace
instead of add
, and when I tried that, pager's fragment (remember, my root view is a pager) that was being displayed disappeared.
I have no idea what's going on, and I'm also new to Android. What am I doing wrong?
Note: My minimum API target in ICS (15
), so I don't need to support any older versions, so any solution involving newer APIs are preferred.