谁能告诉我为什么这不起作用?自从上次工作以来,我没有更改此文件,但现在我收到以下错误:
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
public class MainActivity extends FragmentActivity {
private final static int NUM_PAGES = 2;
private ViewPager mPager;
private ScreenSlidePagerAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.pager);
mAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
mPager.setAdapter(mAdapter);
mPager.setCurrentItem(2);
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
Fragment frag = null;
switch (i) {
case 0:
frag = new PageOneFragment();
break;
case 1:
frag = new PageTwoFragment();
break;
}
return frag;
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
}
错误出现在“frag = new PageTwoFragment();”上 其中指出“类型不匹配:无法从 PageTwoFragment 转换为 Fragment”。
也许我应该从现在开始创建两个项目,最后一个好版本,然后是当前工作项目。这是别人做的吗?
谢谢