Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getSupportFragmentManager().beginTransaction().add(android.R.id.content, f) not working

// Place an ArticleFragment as our content pane
final ArticleFragment f = new ArticleFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, f).commit();

This lines of code are from the NewsReader sample app

Why they are not working if the activity extends ActionBarActivity? Everything works fine if the activity extends FragmentActivity.

Update:

Not working means: The ArticleFragment don't becomes visible and it happens on devices with Android < 4.x, maybe < 3.x but I don't have a device with Android 3.x to test it.

Why?

Ralph

like image 294
Ralph Bergmann Avatar asked Dec 13 '25 18:12

Ralph Bergmann


1 Answers

android.R.id.content does not work on Android 2.3 and below when using ActionBarActivity. There is a bug filed for this, though I am skeptical that it will get addressed. The only workaround I found was to call setContentView() with your own FrameLayout and use it as the target of your FragmentTransaction.

like image 114
CommonsWare Avatar answered Dec 15 '25 08:12

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!