我在LogCat中收到一条警告,说无效的int:“”。我将源跟踪到以下代码片段:
List<Fragment> fragments = getFragments();
PagerAdapter pageAdapter = new PagerAdapter(getSupportFragmentManager(), fragments);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(pageAdapter);
最后一行似乎是罪魁祸首。我不知道为什么,但如果我发表评论,我就不会收到错误。
编辑:
PagerAdapter.java
public class PagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}
getFragments方法
private List<Fragment> getFragments() {
List<Fragment> fList = new ArrayList<Fragment>();
fList.add(new Fragment1());
fList.add(new Fragment2());
return fList;
}