我正在尝试从非活动类打开SherlockFragment活动 从正常活动中使用它
Android.app.Activity>> NonActivityClass>> SherlockFragmentActivity
将此项从Activity类传递给NonActivityClass并尝试启动SherlockFragmentActivity
代码 -
private void changeFragment(Activity act) {
Fragment profileFrag = new New_ProfileFragment();
FragmentTransaction transaction = ((SherlockFragmentActivity) act)
.getSupportFragmentManager().beginTransaction();
try {
((SherlockFragmentActivity) act).getSupportFragmentManager()
.popBackStackImmediate(profileFrag.toString(),
FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (java.lang.IllegalStateException e) {
}
transaction.addToBackStack(profileFrag.toString());
transaction.replace(R.id.content_frame, profileFrag);
transaction.commitAllowingStateLoss();
((SherlockFragmentActivity) act).getSupportFragmentManager()
.executePendingTransactions();
}
我收到错误
FragmentTransaction transaction = ((SherlockFragmentActivity) act)
.getSupportFragmentManager().beginTransaction();
异常 - java.lang.ClassCastException:无法将活动强制转换为com.actionbarsherlock.app.SherlockFragmentActivity
答案 0 :(得分:1)
一个。您是否知道ActionBarSherlock已被弃用了2年?
湾
活动无法投射到 com.actionbarsherlock.app.SherlockFragmentActivity
几乎说了一切。您无法将android.app.Activity
投射到SherlockFragmentActivity
,因为来自what I can see SherlockFragmentActivity
并未延长android.app.Activity
。
℃。你要么必须
activity.getFragmentManager()
或者,如果您必须使用SupportFragmentManager
,则第一项活动必须是android.support.v4.app.FragmentActivity
,以便您可以
activity.getSupportFragmentManager()
无论哪种方式,摆脱ActionBarSherlock
。