android studio上的不兼容类型错误

时间:2015-03-30 00:45:52

标签: android android-studio parse-platform incompatibletypeerror

我无法理解问题所在。我以前使用列表视图做了完全相同的事情,我必须将结果从Parse数据库传递到列表视图适配器,它完美地工作。

@Override
    protected void onPostExecute(Void result) {
        // Locate the listview in listview_main.xml
        viewPager = (ViewPager) findViewById(R.id.pager);
        // Pass the results into ListViewAdapter.java
         adapter = new ViewPagerAdapter(GalleryViewTest.this, worldpopulationlist);

        // Binds the Adapter to the ListView
        viewPager.setAdapter(adapter);
        // Close the progressdialog

        mProgressDialog.dismiss();

以下代码行导致错误。

  

adapter = new ViewPagerAdapter(GalleryViewTest.this,worldpopulationlist);

将鼠标悬停在错误上会产生以下消息:

  

不兼容的类型。

     

必需:android.support.v4.view.PagerAdapter   找到:com.example.gallerypaseupload.galleryview.ViewPagerAdapter

1 个答案:

答案 0 :(得分:0)

更改此

adapter = new ViewPagerAdapter(GalleryViewTest.this, worldpopulationlist);

adapter = new ViewPagerAdapter(getSupportFragmentManager());

您的View Pager适配器看起来像这样

public class ViewPagerAdapter extends FragmentPagerAdapter {
private int pagerCount = 3;

public ViewPagerAdapter(FragmentManager fm) {
    super(fm);
}

//Return the fragments
@Override
public Fragment getItem(int i) {
    switch (i) {

        case 0:
            return Frag1.create(i);

        case 1:
            return Frag2.create(i);
        case 2:
            return Frag3.create(i);



        default:
            return Frag1.create(i);
    }

}

@Override
public int getCount() {
    return pagerCount;
}
}

片段跟随

public class Frag1 extends Fragment{

public static final String ARG_PAGE = "page";



public Frag1 () {
}

public static Frag1 create(int pageNumber) {
    Frag1 fragment = new Frag1();
    Bundle args = new Bundle();
    args.putInt(ARG_PAGE, pageNumber);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    pageNumber = getArguments().getInt(ARG_PAGE);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout .
    rootView = (ViewGroup) inflater.inflate(R.layout.frag1, container, false);
    initComponents();
    return rootView;
}}

这与使用fragments.same的视图寻呼机转换有关。您可以做到这一点。

查看寻呼机图像滑块http://androidopentutorials.com/android-image-slideshow-using-viewpager/