user1910290
user1910290

Reputation: 537

getSupportFragmentManager() method is undefined

I have a Main activity which extends SherlockActivity

The following code seems to be giving me trouble

PopularFragment fragment = new PopularFragment();
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                           .replace(R.id.content_frame, fragment)
                           .commit();

I get the error "Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager"

I tried getSupportFragmentManager() but that gives me this error "The method getSupportFragmentManager() is undefined for the type Main.DrawerItemClickListener"

I am playing with the new android navigation drawer, in my libs/ folder I only have support library v13

my fragments imports are import android.support.v4.app.Fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;

How do I solve this issue? Thanks!

Upvotes: 4

Views: 10306

Answers (3)

Felipez
Felipez

Reputation: 468

I don't know if it is a good practice, But I have changed with newFragment.show(this.getFragmentManager(), "datePicker"); And the datePicker is working.

Upvotes: 2

Nik
Nik

Reputation: 7214

Try:

YourActivityClassName.this.getSupportFragmentManager();

Upvotes: 0

Lingviston
Lingviston

Reputation: 5671

You should extend SherlockFragmentActivity not SherlockActivity. And call getSupportFragmentManager instead of getFragmentManager.

Upvotes: 19

Related Questions