@Override
 public void onClick(View v) {
   fraTra = getChildFragmentManager().beginTransaction();
   switch (v.getId()) {
     case R.id.btn_girl:
       btn_girl.setTextColor(getResources().getColor(R.color.pciture_blue));
       btn_boy.setTextColor(getResources().getColor(R.color.pciture_text));
       if (boy_fragment != null) {
         fraTra.hide(boy_fragment);
       }
       fraTra.show(gril_fragment);
       break;
     case R.id.btn_boy:
       btn_boy.setTextColor(getResources().getColor(R.color.pciture_blue));
       btn_girl.setTextColor(getResources().getColor(R.color.pciture_text));
       if (boy_fragment == null) {
         boy_fragment = new BoyFragment();
         fraTra.add(R.id.main_layout, boy_fragment);
       } else {
         gril_fragment.onResume();
       }
       if (gril_fragment != null) {
         fraTra.hide(gril_fragment);
       }
       fraTra.show(boy_fragment);
       break;
     default:
       break;
   }
   fraTra.commit();
 }
  public void changeFragment() {
    FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
    trx.hide(loginNotFragment);
    trx.hide(fragments[currentTabIndex]);
    // 将之前tab设为未选中状态
    mTabs[currentTabIndex].setSelected(false);
    // 更新当前tab值
    currentTabIndex = index;
    // 把当前tab设为选中状态
    mTabs[currentTabIndex].setSelected(true);

    if (currentTabIndex != 0 && currentTabIndex != 1) {
      SSOAuth ssoAuth = SSOAuth.getInstance(this);
      if (ssoAuth.getCurrUser() == null) {
        if (!loginNotFragment.isAdded()) {
          trx.add(R.id.fragment_container, loginNotFragment);
        }
        trx.show(loginNotFragment).commit();
        return;
      }
    }

    if (!fragments[currentTabIndex].isAdded()) {
      trx.add(R.id.fragment_container, fragments[currentTabIndex]);
    }
    trx.show(fragments[currentTabIndex]).commit();
  }
예제 #3
0
  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {

    if (tab.getPosition() == 0) {
      // Check if the fragment is already initialized
      mMapFragment = getSupportFragmentManager().findFragmentByTag("map");
      if (mMapFragment == null) {
        // If not, instantiate and add it to the activity
        mMapFragment = new ViewMapFragment_();
        ft.add(R.id.container, mMapFragment, "map");
      } else {
        // If it exists, simply attach it in order to show it
        ft.show(mMapFragment);
      }
    }
    if (tab.getPosition() == 1) {
      // Check if the fragment is already initialized
      mMapFragment = getSupportFragmentManager().findFragmentByTag("list");
      if (mListFragment == null) {
        // If not, instantiate and add it to the activity
        //	mListFragment = new RestroomListFragment_();
        ft.add(R.id.container, mListFragment, "list");
      } else {
        // If it exists, simply attach it in order to show it
        ft.show(mListFragment);
      }
    }
  }
예제 #4
0
  public static void RecreateFragemnt(
      FragmentManager manager, String fragmentName, int containerId, String tag) {
    List<Fragment> fragments = manager.getFragments();
    FragmentTransaction transaction = manager.beginTransaction();
    boolean isexist = false;
    try {
      for (Fragment fragment : fragments) {
        transaction.hide(fragment);
        if (fragment.getClass().toString().contains(fragmentName)) {
          transaction.remove(fragment);
          Class c = Class.forName(fragmentName);
          Fragment newfragment = (Fragment) c.newInstance();
          transaction.add(containerId, newfragment, tag);
          isexist = true;
          transaction.show(newfragment);
        }
      }
      if (!isexist) {
        Class c = Class.forName(fragmentName);
        Fragment newfragment = (Fragment) c.newInstance();
        transaction.add(containerId, newfragment, tag);
        transaction.show(newfragment);
      }
      transaction.commit();
    } catch (Exception ex) {

    }
  }
예제 #5
0
  public void removeCurrent() {
    if (currentFragment != null) {
      currentFragment.setPrimaryFragment(false);
    }
    Fragment oldFrag = currentFragment;

    currentFragment = backStack.remove(backStack.size() - 1);
    currentFragment.setPrimaryFragment(true, false);
    supportInvalidateOptionsMenu();

    if (secondaryContainer == null) {
      FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
      trans.setCustomAnimations(
          R.anim.enter_from_left,
          R.anim.exit_to_right,
          R.anim.enter_from_right,
          R.anim.exit_to_left);
      trans.remove(oldFrag);
      trans.show(currentFragment);
      trans.commit();
    } else {
      FragmentTransaction trans = getSupportFragmentManager().beginTransaction();

      // Remove old right fragment
      trans.setCustomAnimations(
          R.anim.enter_from_left,
          R.anim.exit_to_right,
          R.anim.enter_from_right,
          R.anim.exit_to_left);
      trans.remove(oldFrag);

      // Only switch places if there is a backstack, otherwise primary container is correct
      if (backStack.size() > 0) {
        trans.setCustomAnimations(0, 0, 0, 0);
        // Add current left fragment to right side
        trans.remove(currentFragment);

        // Make sure remove is finished before adding
        trans.commit();
        getSupportFragmentManager().executePendingTransactions();

        trans = getSupportFragmentManager().beginTransaction();
        // trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right,
        // R.anim.enter_from_right, R.anim.exit_to_left);
        trans.add(
            R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");

        SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
        newLeftFragment.setSecondaryFragment(true);
        trans.show(newLeftFragment);
      } else {
        secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right));
        secondaryContainer.setVisibility(View.GONE);
      }

      trans.commit();
    }
    recreateSpinner();
  }
 // Update fragment visibility based on current check box state.
 void updateFragmentVisibility() {
   FragmentTransaction ft = getChildFragmentManager().beginTransaction();
   if (mCheckBox1.isChecked()) ft.show(mFragment1);
   else ft.hide(mFragment1);
   if (mCheckBox2.isChecked()) ft.show(mFragment2);
   else ft.hide(mFragment2);
   ft.commit();
 }
  private void setTabSelection(int index) {
    // 开启一个Fragment事务
    FragmentTransaction transaction = manager.beginTransaction();
    clearState();
    hideFragments(transaction);
    switch (index) {
      case 0:
        //                ivHome.setImageResource(R.mipmap.home_select);
        UtilAnimation.scaleView(ivHome, R.mipmap.home_select);
        tvHome.setTextColor(0xffffffff);
        if (homeFragment == null) {
          homeFragment = new HomeFragment();
          transaction.add(R.id.activity_layout, homeFragment);
        } else {
          transaction.show(homeFragment);
        }
        break;

      case 1:
        //                ivType.setImageResource(R.mipmap.type_select);
        UtilAnimation.scaleView(ivType, R.mipmap.type_select);
        tvType.setTextColor(0xffffffff);
        if (typeFragment == null) {
          typeFragment = new TypeFragment();
          transaction.add(R.id.activity_layout, typeFragment);
        } else {
          transaction.show(typeFragment);
        }
        break;
      case 2:
        //                ivFood.setImageResource(R.mipmap.food_select);
        UtilAnimation.scaleView(ivFood, R.mipmap.food_select);
        tvFood.setTextColor(0xffffffff);
        if (foodFragment == null) {
          foodFragment = new FoodFragment();
          transaction.add(R.id.activity_layout, foodFragment);
        } else {
          transaction.show(foodFragment);
        }
        break;
      case 3:
        //                ivMine.setImageResource(R.mipmap.mine_select);
        tvMine.setTextColor(0xffffffff);
        UtilAnimation.scaleView(ivMine, R.mipmap.mine_select);
        if (mineFragment == null) {
          mineFragment = new MineFragment();
          transaction.add(R.id.activity_layout, mineFragment);
        } else {
          transaction.show(mineFragment);
        }
        break;

      default:
        break;
    }
    transaction.commit();
  }
  private void setSelect(int num) {
    set2normal();
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    hideFragment(transaction);
    switch (num) {
      case ConstantUtils.NUMBER.ZERO:
        mTabImg1.setImageResource(R.drawable.fragment_tab_1_sel);
        mTabText1.setTextColor(getResources().getColor(R.color.main_tab_text_select));
        mHeadText.setText(mTabText1.getText().toString());
        if (null == mFrag1) {
          mFrag1 = new FragmentStatic("fragment_tab");
          transaction.add(R.id.fragment_tab_content, mFrag1);
        } else {
          transaction.show(mFrag1);
        }
        break;
      case ConstantUtils.NUMBER.TWO:
        mTabImg2.setImageResource(R.drawable.fragment_tab_2_sel);
        mTabText2.setTextColor(getResources().getColor(R.color.main_tab_text_select));
        mHeadText.setText(mTabText2.getText().toString());
        if (null == mFrag2) {
          mFrag2 = new FragmentDynamic();
          transaction.add(R.id.fragment_tab_content, mFrag2);
        } else {
          transaction.show(mFrag2);
        }
        break;
      case ConstantUtils.NUMBER.THREE:
        mTabImg3.setImageResource(R.drawable.fragment_tab_3_sel);
        mTabText3.setTextColor(getResources().getColor(R.color.main_tab_text_select));
        mHeadText.setText(mTabText3.getText().toString());
        if (null == mFrag3) {
          mFrag3 = new FragmentLife1();
          transaction.add(R.id.fragment_tab_content, mFrag3);
        } else {
          transaction.show(mFrag3);
        }
        break;
      case ConstantUtils.NUMBER.FOUR:
        mTabImg4.setImageResource(R.drawable.fragment_tab_4_sel);
        mTabText4.setTextColor(getResources().getColor(R.color.main_tab_text_select));
        mHeadText.setText(mTabText4.getText().toString());
        if (null == mFrag4) {
          mFrag4 = new FragmentLife2();
          transaction.add(R.id.fragment_tab_content, mFrag4);
        } else {
          transaction.show(mFrag4);
        }
        break;

      default:
        break;
    }
    transaction.commit();
  }
예제 #9
0
  @Override
  public void onClick(View arg0) {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    for (int i = 0; i < mFragments.length; i++) {
      if (mFragments[i] != null) {
        fragmentTransaction.hide(mFragments[i]);
      }
    }
    switch (arg0.getId()) {
      case R.id.home:
        if (mFragments[0] != null) {
          fragmentTransaction.show(mFragments[0]);
        } else {
          fragmentTransaction.add(R.id.zhuye_content, fghome).show(fghome);
          mFragments[0] = fghome;
        }
        fragmentTransaction.commit();

        break;

      case R.id.session:
        if (mFragments[1] != null) {
          fragmentTransaction.show(mFragments[1]);
        } else {
          fragmentTransaction.add(R.id.zhuye_content, fsession).show(fsession);
          mFragments[1] = fsession;
        }
        fragmentTransaction.commit();
        break;

      case R.id.person:
        if (mFragments[2] != null) {
          fragmentTransaction.show(mFragments[2]);
        } else {
          fragmentTransaction.add(R.id.zhuye_content, fperson).show(fperson);
          mFragments[2] = fperson;
        }
        fragmentTransaction.commit();
        break;
      case R.id.nearby:
        if (mFragments[3] != null) {
          fragmentTransaction.show(mFragments[3]);
        } else {
          fragmentTransaction.add(R.id.zhuye_content, fNearby).show(fNearby);
          mFragments[3] = fNearby;
        }
        fragmentTransaction.commit();
        break;

      default:
        break;
    }
  }
예제 #10
0
  public void setChioceItem(int index) {
    if (fManager == null) {
      return;
    }
    FragmentTransaction transaction = fManager.beginTransaction();
    hideFragments(transaction);
    switch (index) {
      case 1:
        if (fhd == null) {
          fhd = new HuDongFragment1();
          transaction.add(R.id.main_fragment, fhd);
        } else {
          transaction.show(fhd);
        }
        break;

      case 2:
        if (fjjy == null) {
          fjjy = new JieYueFragment2();
          transaction.add(R.id.main_fragment, fjjy);
        } else {
          transaction.show(fjjy);
        }
        break;
      case 3:
        if (fqz == null) {
          fqz = new QiangZuoFragment3();
          transaction.add(R.id.main_fragment, fqz);
        } else {
          transaction.show(fqz);
        }
        break;
      case 4:
        if (fxs == null) {
          fxs = new XinShengDaoHangFragment4();
          transaction.add(R.id.main_fragment, fxs);
        } else {
          transaction.show(fxs);
        }

        break;
      case 5:
        if (ffaxian == null) {
          ffaxian = new FaXianFragment5();
          transaction.add(R.id.main_fragment, ffaxian);
        } else {
          transaction.show(ffaxian);
        }
        break;
    }
    transaction.commit();
  }
예제 #11
0
  // 底部按钮的点击事件
  @Override
  public void onCheckedChanged(RadioGroup group, int checkedId) {
    // TODO Auto-generated method stub
    // 得到一个碎片管理器
    fragmentManager = this.getSupportFragmentManager();
    // 开始准备切换
    fragmentTransaction = fragmentManager.beginTransaction();

    if (allSchoolFragment != null) {
      fragmentTransaction.hide(allSchoolFragment);
    }
    if (zhaoSchoolFragment != null) {
      fragmentTransaction.hide(zhaoSchoolFragment);
    }
    if (colSchoolFragment != null) {
      fragmentTransaction.hide(colSchoolFragment);
    }

    switch (checkedId) {
      case R.id.allschool_rg_index:
        if (allSchoolFragment == null) {
          allSchoolFragment = new AllSchoolFragment();
          fragmentTransaction.add(R.id.allschool_fl, allSchoolFragment);
        } else {
          fragmentTransaction.show(allSchoolFragment);
        }
        break;
      case R.id.inschool_rg_bm:
        if (zhaoSchoolFragment == null) {
          zhaoSchoolFragment = new ZhaoSchoolFragment();
          fragmentTransaction.add(R.id.allschool_fl, zhaoSchoolFragment);
        } else {
          fragmentTransaction.show(zhaoSchoolFragment);
        }
        break;
      case R.id.colschool_rg_sc:
        if (colSchoolFragment == null) {
          colSchoolFragment = new ColSchoolFragment();
          fragmentTransaction.add(R.id.allschool_fl, colSchoolFragment);
        } else {
          fragmentTransaction.show(colSchoolFragment);
        }
        break;

      default:
        break;
    }

    // 选择好Fragment进行提交
    fragmentTransaction.commit();
  }
예제 #12
0
  public void setChioceItem(int index) {

    FragmentTransaction transaction = fManager.beginTransaction();
    clearChioce();
    hideFragments(transaction);
    switch (index) {
      case 0:
        meet_image.setImageResource(R.drawable.ic_tabbar_contacts_pressed);
        meet_text.setTextColor(blue);
        meet_layout.setBackgroundResource(R.drawable.ic_tabbar_bg_click);
        if (fg1 == null) {

          fg1 = new fg1();
          transaction.add(R.id.content, fg1);
        } else {

          transaction.show(fg1);
        }
        break;

      case 1:
        contacts_image.setImageResource(R.drawable.ic_tabbar_contacts_pressed);
        contacts_text.setTextColor(blue);
        contacts_layout.setBackgroundResource(R.drawable.ic_tabbar_bg_click);
        if (fg2 == null) {

          fg2 = new fg2();
          transaction.add(R.id.content, fg2);
        } else {

          transaction.show(fg2);
        }
        break;

      case 2:
        settings_image.setImageResource(R.drawable.ic_tabbar_settings_pressed);
        settings_text.setTextColor(blue);
        settings_layout.setBackgroundResource(R.drawable.ic_tabbar_bg_click);
        if (fg3 == null) {

          fg3 = new fg3();
          transaction.add(R.id.content, fg3);
        } else {

          transaction.show(fg3);
        }
        break;
    }
    transaction.commit();
  }
예제 #13
0
  // 定义一个选中一个item后的处理
  public void setChioceItem(int index) {
    // 重置选项+隐藏所有Fragment
    FragmentTransaction transaction = fManager.beginTransaction();
    clearChioce();
    hideFragments(transaction);
    switch (index) {
      case 0:
        course_image.setImageResource(R.drawable.index_home_press);
        course_text.setTextColor(this.getResources().getColor(R.color.red));
        //                course_layout.setBackgroundResource(R.drawable.ic_tabbar_bg_click);
        if (fg1 == null) {
          // 如果fg1为空,则创建一个并添加到界面上
          fg1 = new HomePageFragment();
          transaction.add(R.id.content, fg1);
        } else {
          // 如果MessageFragment不为空,则直接将它显示出来
          transaction.show(fg1);
        }
        break;

      case 1:
        found_image.setImageResource(R.drawable.index_rank_press);
        found_text.setTextColor(this.getResources().getColor(R.color.red));
        //                found_layout.setBackgroundResource(R.drawable.ic_tabbar_bg_click);
        if (fg2 == null) {
          // 如果fg1为空,则创建一个并添加到界面上
          fg2 = new RankingFragment();
          transaction.add(R.id.content, fg2);
        } else {
          // 如果MessageFragment不为空,则直接将它显示出来
          transaction.show(fg2);
        }
        break;

      case 2:
        settings_image.setImageResource(R.drawable.index_personal_press);
        settings_text.setTextColor(this.getResources().getColor(R.color.red));
        //                settings_layout.setBackgroundResource(R.drawable.ic_tabbar_bg_click);
        if (fg3 == null) {
          // 如果fg1为空,则创建一个并添加到界面上
          fg3 = new PersonalFragment();
          transaction.add(R.id.content, fg3);
        } else {
          // 如果MessageFragment不为空,则直接将它显示出来
          transaction.show(fg3);
        }
        break;
    }
    transaction.commit();
  }
예제 #14
0
 /**
  * 显示一个Fragment
  *
  * @param fragment
  */
 public void showFragment(Fragment fragment) {
   if (fragment.isHidden()) {
     FragmentTransaction fragmentTransaction = getFragmentTransaction();
     fragmentTransaction.show(fragment);
     fragmentTransaction.commit();
   }
 }
예제 #15
0
  @Override
  public void initView() {

    fm = getSupportFragmentManager();
    ft = fm.beginTransaction();
    bt_home = (Button) findViewById(R.id.bt_home);
    bt_search = (Button) findViewById(R.id.bt_search);
    bt_message = (Button) findViewById(R.id.bt_message);
    bt_user = (Button) findViewById(R.id.bt_user);
    unreadLabel = (TextView) findViewById(R.id.unread_msg_number);

    //        if (fm.findFragmentByTag("HOME") == null) {
    ft.add(R.id.rl_fragment_contanier, (HomeFragment) FragmentFactory.getFragment(HOME), "HOME")
        .add(
            R.id.rl_fragment_contanier,
            (MessageFragment) FragmentFactory.getFragment(MESSAGE),
            "MESSAGE")
        .hide((MessageFragment) FragmentFactory.getFragment(MESSAGE))
        .add(
            R.id.rl_fragment_contanier,
            (FindFragment) FragmentFactory.getFragment(LOOKINGFORTEACHER),
            "LOOKINGFORTEACHER")
        .hide((FindFragment) FragmentFactory.getFragment(LOOKINGFORTEACHER))
        .add(R.id.rl_fragment_contanier, FragmentFactory.getFragment(MYINFO), "MYINFO")
        .hide(((MyFragment) FragmentFactory.getFragment(MYINFO)));
    ft.show((HomeFragment) FragmentFactory.getFragment(HOME)).commit();
    bt_home.setCompoundDrawablesWithIntrinsicBounds(
        null, getResources().getDrawable(R.mipmap.tab_ico_home_pre), null, null);
    //        bt_home.setSelected(true);
    showLogD("==============================================");
  }
예제 #16
0
  private FragmentTransaction doTabChanged(String tabId, FragmentTransaction ft) {
    TabInfo newTab = null;
    for (int i = 0; i < mTabs.size(); i++) {
      TabInfo tab = mTabs.get(i);
      if (tab.tag.equals(tabId)) {
        newTab = tab;
      }
    }
    if (newTab == null) {
      throw new IllegalStateException("No tab known for tag " + tabId);
    }
    if (mLastTab != newTab) {
      if (ft == null) {
        ft = mFragmentManager.beginTransaction();
      }
      if (mLastTab != null) {
        if (mLastTab.fragment != null) {
          //					ft.detach(mLastTab.fragment);
          ft.hide(mLastTab.fragment);
        }
      }
      if (newTab != null) {
        if (newTab.fragment == null) {
          newTab.fragment = Fragment.instantiate(mContext, newTab.clss.getName(), newTab.args);
          ft.add(mContainerId, newTab.fragment, newTab.tag);
        } else {
          //					ft.attach(newTab.fragment);
          ft.show(newTab.fragment);
        }
      }

      mLastTab = newTab;
    }
    return ft;
  }
예제 #17
0
  private void chaCheFragment() {
    tv_head_titled.setText(R.string.tv_head_chache);
    ib_main_chache.setImageResource(R.drawable.chache2);
    tv_main_chache.setTextColor(Color.parseColor("#3A8BCC"));

    if (chacheFragment == null) {
      // 如果chacheFragment为空,则创建一个并添加到界面上
      chacheFragment = new ChaCheFragment();
      transaction.add(R.id.fl_main_center, chacheFragment);

    } else {
      // 如果chacheFragment不为空,则直接将它显示出来
      transaction.show(chacheFragment);
      // transaction.attach(chacheFragment);replace()

    }

    iv_head_two.setVisibility(View.GONE);
    tv_head_save.setVisibility(View.VISIBLE);
    tv_head_save.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            saveCarCheckCarOrder();
          }
        });
  }
예제 #18
0
 /**
  * button点击事件
  *
  * @param view
  */
 public void onTabClicked(View view) {
   switch (view.getId()) {
     case R.id.btn_conversation:
       index = 0;
       break;
     case R.id.btn_address_list:
       index = 1;
       break;
     case R.id.btn_setting:
       index = 2;
       break;
   }
   if (currentTabIndex != index) {
     FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
     trx.hide(fragments[currentTabIndex]);
     if (!fragments[index].isAdded()) {
       trx.add(R.id.fragment_container, fragments[index]);
     }
     trx.show(fragments[index]).commit();
   }
   mTabs[currentTabIndex].setSelected(false);
   // 把当前tab设为选中状态
   mTabs[index].setSelected(true);
   currentTabIndex = index;
 }
  private void switchRecentlyReportFragment() {

    switchActionBar(true);
    FragmentManager fm = getChildFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    if (recentFragment == null) {
      // recentFragment = new BORecentTrendFragment();
      BloodOxygenRecentlyController controller = new BloodOxygenRecentlyController();
      recentFragment =
          (BloodOxygenRecentTrendFragment)
              controller.getFragment(
                  AbstractUsePagingTaskCacheController.MEASURE_TYPE_RECENTLY, false);
    }
    if (!recentFragment.isAdded()) {
      if (monthFragment != null) {
        ft.hide(monthFragment);
      }
      ft.add(id.fragment_container, recentFragment);
    } else {
      if (monthFragment != null) {
        ft.hide(monthFragment);
      }
      ft.show(recentFragment);
    }
    ft.commitAllowingStateLoss();
  }
예제 #20
0
 /**
  * 切换界面
  *
  * @param oldPosition 旧位置 第一次这里应该时-1
  * @param newPosition 新位置
  * @param isAnim 是否使用预设动画
  */
 protected void switchFragment(int oldPosition, int newPosition, boolean isAnim) {
   if (oldPosition == newPosition) return;
   FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
   // 切换前检查是否有预制动画
   onSwitchFragmentAnim(oldPosition, newPosition, isAnim, ft);
   BasicFragment newFragment =
       (BasicFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(newPosition));
   BasicFragment oldFragment =
       (BasicFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(oldPosition));
   if (newFragment != null) {
     newFragment.setMenuVisibility(true);
     newFragment.setUserVisibleHint(true);
     ft.show(newFragment);
   } else {
     newFragment = fragments[newPosition];
     ft.add(
         getResources().getIdentifier("container", "id", getPackageName()),
         newFragment,
         String.valueOf(newPosition));
   }
   if (oldFragment != null) {
     ft.hide(oldFragment);
   }
   // 切换Fragment后触发switchFragmentAfter方法
   onSwitchFragmentAfter(ft, oldFragment, newFragment);
   ft.commitAllowingStateLoss();
   getSupportFragmentManager().executePendingTransactions();
   currentPosition = newPosition;
 }
예제 #21
0
 /** 打开fragment并展示 */
 public void showFragment(int position) {
   hideFragments();
   MyFragment fragment = mFragmentList.get(position);
   FragmentTransaction ft = mFragmentManager.beginTransaction();
   ft.show(fragment);
   ft.commitAllowingStateLoss();
 }
예제 #22
0
  public void switchContent(Fragment fragment) {
    try {
      FragmentTransaction t = fm.beginTransaction();
      List<Fragment> flist = fm.getFragments();
      if (flist == null) {
        t.add(R.id.main_content, fragment);
      } else {
        if (!flist.contains(fragment)) {
          t.add(R.id.main_content, fragment);
        }
        t.hide(slist.get(slist.size() - 1));
        t.show(fragment);
      }

      if (slist.contains(fragment)) {
        slist.remove(fragment);
      }

      slist.add(fragment);

      t.commitAllowingStateLoss();

    } catch (Exception e) {
    }
  }
 public void onKeyboardShow() {
   Log.i("KeyboardFragment", "Showing keyboard");
   FragmentManager fm = getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   ft.show(this);
   ft.commit();
 }
예제 #24
0
  protected void showFragment(Fragment oldFragment, Fragment newFragment) {
    android.support.v4.app.Fragment currentFragment =
        getSupportFragmentManager().findFragmentByTag(newFragment.getFragmentTag());

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    if (currentFragment != null) {
      if (oldFragment != null) transaction.hide(oldFragment);

      if (currentFragment.isDetached()) transaction.attach(currentFragment);

      transaction.show(currentFragment);
    } else {
      if (oldFragment != null) transaction.hide(oldFragment);

      if (newFragment != null) {
        if (newFragment.isDetached()) {
          transaction.attach(newFragment);
        } else {
          transaction.add(R.id.MainLayout, newFragment, newFragment.getFragmentTag());
        }
      }
    }

    if (oldFragment != null) transaction.addToBackStack(null);

    transaction.commit();
  }
예제 #25
0
 @Override
 public void onItemSelected(int checkedId) {
   hideFragments();
   switch (checkedId) {
     case R.id.radio_main:
       if (AppData.getInstance().getBorrowRequestInfo() != null) {
         if (borrowApplyFragment == null) {
           borrowApplyFragment = BorrowApplyFragment.newInstance();
           fragmentTransaction.add(R.id.main_content, borrowApplyFragment, Constants.BORROWAPPLY);
         }
         fragmentTransaction.show(borrowApplyFragment);
       } else {
         if (staffStateFragment == null) {
           if (messageCenterFragment != null) messageCenterFragment.refreshData();
           staffStateFragment = StaffStateFragment.newInstance();
           fragmentTransaction.add(R.id.main_content, staffStateFragment, Constants.STAFFSTATE);
         }
         fragmentTransaction.show(staffStateFragment);
       }
       break;
     case R.id.radio_repayment:
       if (repaymentListFragment == null) {
         repaymentListFragment = RepaymentListFragment.newInstance();
         fragmentTransaction.add(R.id.main_content, repaymentListFragment, Constants.REPAYMENT);
       }
       fragmentTransaction.show(repaymentListFragment);
       break;
     case R.id.radio_message:
       if (messageCenterFragment == null) {
         messageCenterFragment = new MessageCenterFragment().newInstance();
         fragmentTransaction.add(
             R.id.main_content, messageCenterFragment, Constants.MESSAGECENTER);
       }
       fragmentTransaction.show(messageCenterFragment);
       break;
     case R.id.radio_setup:
       if (settingFragment == null) {
         settingFragment = SettingFragment.newInstance();
         fragmentTransaction.add(R.id.main_content, settingFragment, Constants.SETTING);
       }
       fragmentTransaction.show(settingFragment);
       break;
     default:
       break;
   }
   fragmentTransaction.commit();
 }
예제 #26
0
  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
    String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
    FragmentManager fm = getSupportFragmentManager();
    currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]);
    currentFragment.setPrimaryFragment(true);
    currentFragment.setSupportTag(ids[0]);
    supportInvalidateOptionsMenu();
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    for (int i = 1; i < size; i++) {
      SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]);
      frag.setSupportTag(ids[i]);
      if (secondaryContainer != null) {
        frag.setPrimaryFragment(false, true);
      }
      trans.hide(frag);
      backStack.add(frag);
    }
    trans.commit();

    // Current fragment is hidden in secondaryContainer
    if (secondaryContainer == null && !currentFragment.isVisible()) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_container, currentFragment, ids[0]);
      trans.commit();
    }
    // Current fragment needs to be moved over to secondaryContainer
    else if (secondaryContainer != null
        && secondaryContainer.findViewById(currentFragment.getRootId()) == null
        && backStack.size() > 0) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.show(backStack.get(backStack.size() - 1));
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
      trans.commit();

      secondaryContainer.setVisibility(View.VISIBLE);
    }

    lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
    if (lastSelectedPosition != 0) {
      MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
      if (item != null) {
        item.setChecked(true);
      }
    }
    recreateSpinner();
  }
예제 #27
0
  private void switchToTab(int tabId) {
    FragmentTransaction tans = mFragmentManager.beginTransaction();
    switch (tabId) {
      case R.id.stock_button:
        mCurrSelectedTabId = R.id.stock_button;

        tans.show(mStockFragment);
        tans.hide(mNoteFragment);
        break;

      case R.id.note_button:
        mCurrSelectedTabId = R.id.note_button;

        tans.hide(mStockFragment);
        tans.show(mNoteFragment);
        break;
    }
    tans.commitAllowingStateLoss();
  }
예제 #28
0
  public void onBookmarkCancel(Bookmark b) {
    if (getSupportFragmentManager().findFragmentById(R.id.maincontent).isHidden()) {
      FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
      transaction.hide(getSupportFragmentManager().findFragmentById(R.id.addcontent));
      transaction.show(getSupportFragmentManager().findFragmentById(R.id.maincontent));
      transaction.commit();
    }

    onBookmarkView(b);
  }
예제 #29
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // Getting status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    // Showing status
    if (status == ConnectionResult.SUCCESS) {

    } else {

      int requestCode = 10;
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
      dialog.show();
      return;
    }

    // requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    if (savedInstanceState != null) {
      allTapItem = (ArrayList<OSMNode>) savedInstanceState.get("allTapItem");
      allToiletItem = (ArrayList<OSMNode>) savedInstanceState.get("allToiletItem");
      allFoodItem = (ArrayList<OSMNode>) savedInstanceState.get("allFoodItem");
    }
    // TODO Semi-Transparent Action Bar
    // requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    // getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));

    setContentView(R.layout.activity_main);
    configureActionBar();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    mMapFragment = getSupportFragmentManager().findFragmentByTag("map");
    if (mMapFragment == null) {
      // If not, instantiate and add it to the activity
      mMapFragment = new ViewMapFragment_();
      ft.add(R.id.container, mMapFragment, "map").commit();
    } else {
      // If it exists, simply attach it in order to show it
      ft.show(mMapFragment).commit();
    }
    TapForTap.initialize(this, "ef3209aec5ac8e0eb9682b8890b20a78");
    adview = (AdView) findViewById(R.id.adView);
    adview.setAdListener(this);
    ImageButton imgbtn = (ImageButton) findViewById(R.id.closeadbtn);
    imgbtn.setVisibility(View.GONE);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    adview.loadAd(request);

    // Search markers
    searchMarkers = new ArrayList<Marker>();
  }
  public void showFragment(Context context) {
    SherlockFragmentActivity activity = (SherlockFragmentActivity) context;
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragTransaction = fragmentManager.beginTransaction();
    Fragment formulaEditorFragment =
        fragmentManager.findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
    fragTransaction.hide(formulaEditorFragment);

    fragTransaction.show(this);
    fragTransaction.commit();
  }