0

My imports:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

class name:

public class MainActivity extends FragmentActivity implements     ViewPager.OnPageChangeListener, EmoticonPickListener {

My adapter:

MyPagerAdapter1 adapterViewPager = new MyPagerAdapter1(this, Arrays.asList(
           GridFragment.newInstance(0, "Page Recent","whatever"),
           GridFragment.newInstance(1, "Page Smile","smile"),
           GridFragment.newInstance(2, "Page Flowers","flower"),
           GridFragment.newInstance(3, "Page Vehiculs","vehicles"),
           GridFragment.newInstance(4, "Page Bell","bell"),
           GridFragment.newInstance(5, "Page Symbol","symbol")
           ));

My pagerAdapter class:

private static class MyPagerAdapter1 extends FragmentStatePagerAdapter {
    private List<GridFragment> fragments;

    public MyPagerAdapter1(FragmentActivity activity, List<GridFragment> list) {
        super(activity.getSupportFragmentManager());
        this.fragments = list;
    }

    @Override
    public Fragment getItem(int i) {
        return fragments.get(i);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }
}

and my fragment definition:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class GridFragment extends Fragment  {

I tried to search for solutions like: [a link]FragmentPagerAdapter troubles and woes: Constructor Undefined but it didnt work

Community
  • 1
  • 1
Hanane
  • 474
  • 6
  • 21

1 Answers1

0

Your constructor accepts a List of GridFragment, which are a particular type of Fragment. If you try to initialize with a List of Fragment, it will not work since the types do not match.

The converse would work: If the constructor accepts a List of Fragments, it would accept a List of GridFragments

Ktipr
  • 111
  • 7