Ralph Bergmann
Ralph Bergmann

Reputation: 3076

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

Upvotes: 3

Views: 14844

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007359

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.

Upvotes: 7

mmoghrabi
mmoghrabi

Reputation: 1291

Because it should extend SherlockFragmentActivity or any other support library, as for previous android versions you will have to add a support library to your lib folder,

However the getSupportFragmentManager works for previous android versions in other words before version 11 if you want your application to work as it is change the getSupportFragmentManager into getFragmentManager and change your minSdkVersion into 11 and targeted into 17, good luck

Upvotes: 0

Related Questions