片段管理器如下所示:
FragmentManager fragmentManager = getSupportFragmentManager();
switch (position) {
case 0:
fragmentManager.beginTransaction()
.replace(R.id.container, ReviewFragment.newInstance(position + 1))
.commit();
break;
case 1:
fragmentManager.beginTransaction()
.replace(R.id.container, RedeemFragment.newInstance(position + 1))
.commit();
break;
case 2:
fragmentManager.beginTransaction()
.replace(R.id.container, MyAccountFragment.newInstance(position + 1))
.commit();
break;
case 3:
ParseUser.logOut();
presentLoginActivity();
break;
}
错误就行了:
case 0:
fragmentManager.beginTransaction()
.replace(R.id.container, ReviewFragment.newInstance(position + 1))
.commit();
,错误如下:
Wrong second argument type. Found: 'blah.blah.blah.MainActivity.ReviewFragment', required: 'android.support.v4.app.Fragment'
CameraFragment来自cwac-camera-0.6.12.jar
public static class ReviewFragment extends CameraFragment
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static ReviewFragment newInstance(int sectionNumber) {
ReviewFragment fragment = new ReviewFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public ReviewFragment() {
}
...
}
我知道CameraFragment是android.app.Fragment,我试过更改getSupportFragmentManager(); to getFragmentManager();并将所有其他Fragment子类更改为android.app.Fragment的子类,但它仍然无法正常工作。想法?
答案 0 :(得分:1)
我的CWAC-Camera库有两个片段实现:
SherlockFragment
,用于ActionBarSherlock操作栏后台,由于历史原因它不包含仅扩展片段backport的Fragment
类的片段。
话虽这么说,创建自己的应该只需要几分钟。将this class复制到您的项目中,并将其更改为扩展android.support.v4.app.Fragment
而不是SherlockFragment
。在快速扫描代码时,我没有看到任何其他需要进行的更改。