android - FragmentTransaction#add(int, Fragment) not doing anything -
i have actionbaractivity
(which, way, extends android.support.v4.app.fragmentactivity
) , want add fragment topmost. here 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
id of root view (whichandroid.support.v4.view.viewpager
)
when code above runs, nothing happens. no exceptions, crashes or visual changes. nothing. i've seen fragmenttransaction not doing anything , there suggestion there telling use replace
instead of add
, , when tried that, pager's fragment (remember, root view pager) being displayed disappeared.
i have no idea what's going on, , i'm new android. doing wrong?
note: minimum api target in ics (15
), don't need support older versions, solution involving newer apis preferred.
i have used viewpager in application , used fragmentstatepageradapter. take care of fragment management you.
you can read more viewpager here.
and fragmentstatepageradapter here.