从非 activity class 打开 SherlockFragment activity?
opening a SherlockFragment activity from non activity class?
我正在尝试从非 activity class 打开 SherlockFragment activity
从正常 activity
使用它
Android.app.Activity >> 非ActivityClass >> Sherlock片段Activity
将此从 Activity class 传递给 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: activity 无法转换为 com.actionbarsherlock.app.SherlockFragmentActivity
一个。您是否知道 ActionBarSherlock 已被弃用 2 年?
b。
activity cannot be cast to
com.actionbarsherlock.app.SherlockFragmentActivity
几乎可以说明一切。您不能将 android.app.Activity
转换为 SherlockFragmentActivity
因为 from what I can see SherlockFragmentActivity
不会扩展 android.app.Activity
。
c。你要么必须做
activity.getFragmentManager()
或者,如果你必须使用 SupportFragmentManager
,你首先 activity 必须是 android.support.v4.app.FragmentActivity
这样你就可以
activity.getSupportFragmentManager()
无论如何,摆脱掉ActionBarSherlock
。
我正在尝试从非 activity class 打开 SherlockFragment activity 从正常 activity
使用它Android.app.Activity >> 非ActivityClass >> Sherlock片段Activity
将此从 Activity class 传递给 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: activity 无法转换为 com.actionbarsherlock.app.SherlockFragmentActivity
一个。您是否知道 ActionBarSherlock 已被弃用 2 年?
b。
activity cannot be cast to com.actionbarsherlock.app.SherlockFragmentActivity
几乎可以说明一切。您不能将 android.app.Activity
转换为 SherlockFragmentActivity
因为 from what I can see SherlockFragmentActivity
不会扩展 android.app.Activity
。
c。你要么必须做
activity.getFragmentManager()
或者,如果你必须使用 SupportFragmentManager
,你首先 activity 必须是 android.support.v4.app.FragmentActivity
这样你就可以
activity.getSupportFragmentManager()
无论如何,摆脱掉ActionBarSherlock
。