|
|
@@ -220,6 +220,8 @@ public class ActMain extends BaseActYmPermissionCheck {
|
|
|
public static final int MIN_CLICK_DELAY_TIME = 200;
|
|
|
private long lastClickTime = 0;
|
|
|
|
|
|
+ private Fragment[] mFragments = new Fragment[3];
|
|
|
+
|
|
|
private void initFragments() {
|
|
|
changeVisible(-1, lastPosition);
|
|
|
//小绵羊3.4.10新增 判断用户是否是游戏用户,是的话默认打开游戏界面
|
|
|
@@ -242,18 +244,24 @@ public class ActMain extends BaseActYmPermissionCheck {
|
|
|
int index = 0;
|
|
|
int iconSize = ScreenUtil.dip2px(this, 30);
|
|
|
for (MainTab mainTab : mainTabs) {
|
|
|
- Fragment fragment = getSupportFragmentManager().findFragmentByTag("fragment_" + index);
|
|
|
- if (fragment == null) {
|
|
|
- fragment = mainTabs[index].getFragment();
|
|
|
- }
|
|
|
- if (!fragment.isAdded()) {
|
|
|
- transaction.add(R.id.frame_container, fragment, "fragment_" + index);
|
|
|
+ mFragments[index] = getSupportFragmentManager().findFragmentByTag("fragment_" + index);
|
|
|
+ if (mFragments[index] == null) {
|
|
|
+ mFragments[index] = mainTabs[index].getFragment();
|
|
|
}
|
|
|
if (index == lastPosition) {
|
|
|
- transaction.show(fragment);
|
|
|
- } else {
|
|
|
- transaction.hide(fragment);
|
|
|
+ if (!mFragments[index].isAdded()) {
|
|
|
+ transaction.add(R.id.frame_container, mFragments[index], "fragment_" + index);
|
|
|
+ }
|
|
|
+ transaction.show(mFragments[index]);
|
|
|
}
|
|
|
+// if (!mFragments[index].isAdded()) {
|
|
|
+// transaction.add(R.id.frame_container, mFragments[index], "fragment_" + index);
|
|
|
+// }
|
|
|
+// if (index == lastPosition) {
|
|
|
+// transaction.show(mFragments[index]);
|
|
|
+// } else {
|
|
|
+// transaction.hide(mFragments[index]);
|
|
|
+// }
|
|
|
View view = tab_container.getChildAt(index);
|
|
|
if (view instanceof TextView) {
|
|
|
((TextView) view).setText(mainTab.getStringId());
|
|
|
@@ -299,6 +307,10 @@ public class ActMain extends BaseActYmPermissionCheck {
|
|
|
}
|
|
|
if (cFragment != null) {
|
|
|
transaction.show(cFragment);
|
|
|
+ } else {
|
|
|
+ cFragment = mFragments[position];
|
|
|
+ transaction.add(R.id.frame_container, mFragments[position], "fragment_" + position);
|
|
|
+ transaction.show(mFragments[position]);
|
|
|
}
|
|
|
transaction.commitAllowingStateLoss();
|
|
|
if (lFragment != null) {
|