rmaik
rmaik

Reputation: 1086

getSupportFragmentManager is not recognized

As shown below in the code, the MainActivity extends FragmentActivity, and TabsPagerAdapter extends FragmentPagerAdapter.

I do not know why eclipse does not recognize this line

viewPager = new TabsPagerAdapter(getSupportFragmentManager(), this.fragList);

MainActivity:

import java.util.List;
import com.example.settingsviewpagertabs.adapter.TabsPagerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
....
....
....
viewPager = new TabsPagerAdapter(getSupportFragmentManager(), this.fragList); //eclipse does not accept it

adapter:

import java.util.List;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsPagerAdapter extends FragmentPagerAdapter {

List<Fragment> mFragList;

public TabsPagerAdapter(FragmentManager fm, List<Fragment> mFragList) {
    super(fm);
    // TODO Auto-generated constructor stub
    this.mFragList = mFragList;
}

@Override
public Fragment getItem(int arg0) {
    // TODO Auto-generated method stub
    return this.mFragList.get(arg0);

}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return this.mFragList.size();
}

}

Update_1:

now i am usinf the below imports,

and when i use the

viewPager = new TabsPagerAdapter(getSupportFragmentManager(), this.fragList);

i receive the below message:

Type mismatch: cannot convert from TabsPagerAdapter to ViewPager

the imports i currently use are:

MainActivity:

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;

adapter imports:

import java.util.List;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

Upvotes: -1

Views: 1712

Answers (2)

Kristy Welsh
Kristy Welsh

Reputation: 8362

You're not importing the right classes (the support ones). Change:

import android.app.Fragment;
import android.app.FragmentTransaction;

to in MainActivity:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

Upvotes: 3

Kingfisher Phuoc
Kingfisher Phuoc

Reputation: 8200

Actually it's not the problem with support fragment manager. It's the problem with your fragment list: look at your tabs adapter, you import import android.support.v4.app.Fragment;. However, in your FragmentActivity, you import import android.app.Fragment;. --> solution is change your import in FragmentActivity.

Upvotes: 1

Related Questions