我也在尝试实施this project,我得到^标题^错误。
我知道此错误已重新发布。见这里:Error: The constructor MainActivity.ScreenSlidePagerAdapter(FragmentManager) is undefined在这里: Eclipse doesnt recognize android.support.v13.app.FragmentActivity although I have android-support-v13 library
但没有一个答案解决了我的问题。也许这些库有问题或者??
这是我的代码。
package kn.screenslide;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
public class ScreenSlideActivity extends FragmentActivity {
//The number of pages (wizard steps) to show in this demo.
private static final int NUM_PAGES = 5;
//The pager widget, which handles animation and allows swiping horizontally to access previous and next wizard steps.
private ViewPager mPager;
//The pager adapter, which provides the pages to the view pager widget.
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_slide);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// When changing pages, reset the action bar actions since they are dependent
// on which page is currently active. An alternative approach is to have each
// fragment expose actions itself (rather than the activity exposing actions),
// but for simplicity, the activity provides the actions in this sample.
invalidateOptionsMenu();
}
});
}
//A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in sequence.
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
//This is where fragments are created
@Override
public android.support.v4.app.Fragment getItem(int position) {
return ScreenSlidePageAdapter.create(position);
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}
答案 0 :(得分:1)
问题在ScreenSlidePageAdapter.getItem()
。适配器没有create()方法。
//This is where fragments are created
@Override
public android.support.v4.app.Fragment getItem(int position) {
return ScreenSlidePageAdapter.create(position);
}
您必须在此处返回片段,而不是适配器。