gpt4 book ai didi

Android 使用 ShelockFragment 而不是 Fragment

转载 作者:行者123 更新时间:2023-11-29 01:34:18 24 4
gpt4 key购买 nike

我正在使用下面的代码在 Fragment 之间切换,没有任何问题:

private void showSelectedItem(int index) {
Fragment mFragment = null;
if (index == mLastMenuItemSelected)
return;
FragmentTransaction fts = getSupportFragmentManager().beginTransaction();
if (mLastViewFragment != null) {
fts.remove(mLastViewFragment);
}
switch (index) {
case SV.MIS_ShowAllSubjects:
mFragment = new FragmentViewAllSubjects();
fts.replace(R.id.SubjectViewFragment, mFragment);
txtSelectedSlideTitle.setText(UC.getString(R.string.slide_menu_main));
break;
}
fts.commit();
mLastMenuItemSelected = index;
mSlidingMenu.showContent(true);
mLastViewFragment = mFragment;
}

现在我想使用 SherlockFragment 而不是 Fragment,为了进行此更改,我将创建新的 Fragment 为:

public class ActionbarTabsPager extends SherlockFragmentActivity {
ViewPager mViewPager;
TabsAdapter mTabsAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {

...

}
}

我想将顶部代码更改为下面的代码以在 SherlockFragment 之间使用和切换:

private void showSelectedItem(int index) {
SherlockFragmentActivity mFragment = null;
if (index == mLastMenuItemSelected)
return;
FragmentTransaction fts = getSupportFragmentManager().beginTransaction();
if (mLastViewFragment != null) {
fts.remove(mLastViewFragment);
}
switch (index) {
case SV.MIS_ShowAllSubjects:
mFragment = new ActionbarTabsPager();
fts.replace(R.id.SubjectViewFragment, mFragment);
txtSelectedSlideTitle.setText(UC.getString(R.string.slide_menu_main));
break;
}
fts.commit();
mLastMenuItemSelected = index;
mSlidingMenu.showContent(true);
mLastViewFragment = mFragment;
}

但我收到这个错误,我无法解决:

Error:(141, 29) java: incompatible types: ir.jaziire.Fragments.ActionbarTabsPager cannot be converted to com.actionbarsherlock.app.SherlockListFragment
Error:(149, 29) java: incompatible types: com.actionbarsherlock.app.SherlockListFragment cannot be converted to com.actionbarsherlock.app.SherlockFragmentActivity

我的问题是:

mFragment = new ActionbarTabsPager();

最佳答案

ActionbarTabsPager 正在扩展 SherlockFragmentActivity,而不是 SherlockFragment。变化

public class ActionbarTabsPager extends SherlockFragmentActivity {

public class ActionbarTabsPager extends SherlockFragment {

SherlockFragmentActivity mFragment = null;

Fragment mFragment = null;

关于Android 使用 ShelockFragment 而不是 Fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29414822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com