构造函数MainActivity.MyPagerAdapter1(MainActivity,List <fragment>)未定义</fragment>

时间:2014-08-26 07:57:33

标签: android eclipse

我的进口商品:

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;

班级名称:

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

我的适配器:

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")
           ));

我的pagerAdapter类:

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();
    }
}

和我的片段定义:

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  {

我试图搜索以下解决方案: [链接] FragmentPagerAdapter troubles and woes: Constructor Undefined 但它没有用

1 个答案:

答案 0 :(得分:0)

您的构造函数接受GridFragment列表,它是特定类型的Fragment。如果您尝试使用片段列表进行初始化,则由于类型不匹配,它将无法工作。

反过来会起作用:如果构造函数接受片段列表,它将接受GridFragments列表