Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 524
user1910290 Avatar asked Nov 30 '22 12:11

user1910290


2 Answers

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

like image 186
Lingviston Avatar answered Dec 04 '22 12:12

Lingviston


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.

like image 23
Felipez Avatar answered Dec 04 '22 14:12

Felipez