Java Code Examples for android.support.v4.app.FragmentTransaction#isEmpty()
The following examples show how to use
android.support.v4.app.FragmentTransaction#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionBarWrapper.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
@Override public void onTabReselected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) { if (mListener != null) { FragmentTransaction trans = null; if (mActivity instanceof FragmentActivity) { trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } mListener.onTabReselected(this, trans); if (trans != null && !trans.isEmpty()) { trans.commit(); } } }
Example 2
Source File: CommentsTimeLinePagerAdapter.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public CommentsTimeLinePagerAdapter(CommentsTimeLineFragment fragment, ViewPager viewPager, FragmentManager fm, SparseArray<Fragment> fragmentList) { super(fm); this.fragmentList = fragmentList; fragmentList.append(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION, fragment.getCommentsToMeTimeLineFragment()); fragmentList.append(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION, fragment.getCommentsByMeTimeLineFragment()); FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction(); if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION).isAdded()) transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION), CommentsToMeTimeLineFragment.class.getName()); if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION).isAdded()) transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION), CommentsByMeTimeLineFragment.class.getName()); if (!transaction.isEmpty()) { transaction.commit(); fragment.getChildFragmentManager().executePendingTransactions(); } }
Example 3
Source File: HotHuaTiViewPagerAdapter.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public HotHuaTiViewPagerAdapter(Fragment fragment, ViewPager viewPager, FragmentManager fm, SparseArray<Fragment> fragmentList, List<String> titleList) { super(fm); this.mFragmentList = fragmentList; this.mTitleList = titleList; for (int i = 0; i < this.mFragmentList.size(); i++) { tagList.append(i, this.mFragmentList.get(i).getClass().getName()); } FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction(); for (int i = 0; i < fragmentList.size(); i++) { Fragment ft = this.mFragmentList.get(i); if (!ft.isAdded()) { transaction.add(viewPager.getId(), mFragmentList.get(i), ft.getClass().getName()); } } if (!transaction.isEmpty()) { transaction.commit(); fragment.getChildFragmentManager().executePendingTransactions(); } }
Example 4
Source File: ViewPagerFragmentAdapter.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public ViewPagerFragmentAdapter(Fragment fragment, ViewPager viewPager, FragmentManager fm, ArrayList<ChildPage> fragmentList) { super(fm); this.mFragmentList = fragmentList; FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction(); for (int i = 0; i < fragmentList.size(); i++) { Fragment ft = this.mFragmentList.get(i).getmFragment(); if (!ft.isAdded()) { transaction.add(viewPager.getId(), ft, ft.getClass().getName() + i); } } if (!transaction.isEmpty()) { transaction.commit(); fragment.getChildFragmentManager().executePendingTransactions(); } }
Example 5
Source File: ViewPagerFragmentAdapter.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public ViewPagerFragmentAdapter(Fragment fragment, ViewPager viewPager, FragmentManager fm, ArrayList<ChildPage> fragmentList) { super(fm); this.mFragmentList = fragmentList; FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction(); for (int i = 0; i < fragmentList.size(); i++) { Fragment ft = this.mFragmentList.get(i).getmFragment(); if (!ft.isAdded()) { transaction.add(viewPager.getId(), ft, ft.getClass().getName() + i); } } if (!transaction.isEmpty()) { transaction.commit(); fragment.getChildFragmentManager().executePendingTransactions(); } }
Example 6
Source File: ActionBarWrapper.java From Libraries-for-Android-Developers with MIT License | 6 votes |
@Override public void onTabReselected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) { if (mListener != null) { FragmentTransaction trans = null; if (mActivity instanceof FragmentActivity) { trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } mListener.onTabReselected(this, trans); if (trans != null && !trans.isEmpty()) { trans.commit(); } } }
Example 7
Source File: ActionBarWrapper.java From zhangshangwuda with Apache License 2.0 | 6 votes |
@Override public void onTabReselected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) { if (mListener != null) { FragmentTransaction trans = null; if (mActivity instanceof FragmentActivity) { trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } mListener.onTabReselected(this, trans); if (trans != null && !trans.isEmpty()) { trans.commit(); } } }
Example 8
Source File: HotHuaTiViewPagerAdapter.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public HotHuaTiViewPagerAdapter(Fragment fragment, ViewPager viewPager, FragmentManager fm, SparseArray<Fragment> fragmentList, List<String> titleList) { super(fm); this.mFragmentList = fragmentList; this.mTitleList = titleList; for (int i = 0; i < this.mFragmentList.size(); i++) { tagList.append(i, this.mFragmentList.get(i).getClass().getName()); } FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction(); for (int i = 0; i < fragmentList.size(); i++) { Fragment ft = this.mFragmentList.get(i); if (!ft.isAdded()) { transaction.add(viewPager.getId(), mFragmentList.get(i), ft.getClass().getName()); } } if (!transaction.isEmpty()) { transaction.commit(); fragment.getChildFragmentManager().executePendingTransactions(); } }
Example 9
Source File: CommentsTimeLinePagerAdapter.java From iBeebo with GNU General Public License v3.0 | 6 votes |
public CommentsTimeLinePagerAdapter(CommentsTimeLineFragment fragment, ViewPager viewPager, FragmentManager fm, SparseArray<Fragment> fragmentList) { super(fm); this.fragmentList = fragmentList; fragmentList.append(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION, fragment.getCommentsToMeTimeLineFragment()); fragmentList.append(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION, fragment.getCommentsByMeTimeLineFragment()); FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction(); if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION).isAdded()) transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION), CommentsToMeTimeLineFragment.class.getName()); if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION).isAdded()) transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION), CommentsByMeTimeLineFragment.class.getName()); if (!transaction.isEmpty()) { transaction.commit(); fragment.getChildFragmentManager().executePendingTransactions(); } }
Example 10
Source File: ActionBarWrapper.java From zen4android with MIT License | 6 votes |
@Override public void onTabReselected(android.app.ActionBar.Tab tab, android.app.FragmentTransaction ft) { if (mListener != null) { FragmentTransaction trans = null; if (mActivity instanceof FragmentActivity) { trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } mListener.onTabReselected(this, trans); if (trans != null && !trans.isEmpty()) { trans.commit(); } } }
Example 11
Source File: ActionBarImpl.java From zhangshangwuda with Apache License 2.0 | 5 votes |
@Override public void selectTab(Tab tab) { if (getNavigationMode() != NAVIGATION_MODE_TABS) { mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION; return; } FragmentTransaction trans = null; if (mActivity instanceof FragmentActivity) { trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } if (mSelectedTab == tab) { if (mSelectedTab != null) { mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans); mTabScrollView.animateToTab(tab.getPosition()); } } else { mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION); if (mSelectedTab != null) { mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans); } mSelectedTab = (TabImpl) tab; if (mSelectedTab != null) { mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans); } } if (trans != null && !trans.isEmpty()) { trans.commit(); } }
Example 12
Source File: ActionBarImpl.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@Override public void selectTab(Tab tab) { if (getNavigationMode() != NAVIGATION_MODE_TABS) { mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION; return; } FragmentTransaction trans = null; if (mActivity instanceof FragmentActivity) { trans = ((FragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } if (mSelectedTab == tab) { if (mSelectedTab != null) { mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans); mTabScrollView.animateToTab(tab.getPosition()); } } else { mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION); if (mSelectedTab != null) { mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans); } mSelectedTab = (TabImpl) tab; if (mSelectedTab != null) { mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans); } } if (trans != null && !trans.isEmpty()) { trans.commit(); } }
Example 13
Source File: MainTimeLineActivity.java From iBeebo with GNU General Public License v3.0 | 5 votes |
private void initFragments() { Fragment timeLineFragment = getMainTimeLineFragment(); Fragment favFragment = getFavFragment(); Fragment hotWeiboFragment = getHotWeiboViewPagerFragment(); Fragment hotHuatiFragment = getHotHuaTiViewPagerFragment(); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); if (!timeLineFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, timeLineFragment, MainTimeLineFragment.class.getName()); fragmentTransaction.hide(timeLineFragment); } if (!favFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, favFragment, MyFavListFragment.class.getName()); fragmentTransaction.hide(favFragment); } if (!hotWeiboFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, hotWeiboFragment, HotWeiboViewPagerFragment.class.getName()); fragmentTransaction.hide(hotWeiboFragment); } if (!hotHuatiFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, hotHuatiFragment, HotHuaTiViewPagerFragment.class.getName()); fragmentTransaction.hide(hotHuatiFragment); } if (!fragmentTransaction.isEmpty()) { fragmentTransaction.commit(); getSupportFragmentManager().executePendingTransactions(); } }
Example 14
Source File: FragmentUtil.java From android-vlc-remote with GNU General Public License v3.0 | 5 votes |
public void removeFragmentsByTag(String... tags) { FragmentTransaction ft = fm.beginTransaction(); for(String tag : tags) { Fragment f = fm.findFragmentByTag(tag); if(f != null) { ft.remove(f); } } if(!ft.isEmpty()) { ft.commit(); fm.executePendingTransactions(); } }
Example 15
Source File: ActionBarImpl.java From android-apps with MIT License | 5 votes |
@Override public void selectTab(Tab tab) { if (getNavigationMode() != NAVIGATION_MODE_TABS) { mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION; return; } FragmentTransaction trans = null; if (mActivity instanceof SherlockFragmentActivity) { trans = ((SherlockFragmentActivity)mActivity).getSupportFragmentManager().beginTransaction() .disallowAddToBackStack(); } if (mSelectedTab == tab) { if (mSelectedTab != null) { mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans); mTabScrollView.animateToTab(tab.getPosition()); } } else { mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION); if (mSelectedTab != null) { mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans); } mSelectedTab = (TabImpl) tab; if (mSelectedTab != null) { mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans); } } if (trans != null && !trans.isEmpty()) { trans.commit(); } }
Example 16
Source File: MainTimeLineActivity.java From iBeebo with GNU General Public License v3.0 | 5 votes |
private void initFragments() { Fragment timeLineFragment = getMainTimeLineFragment(); Fragment favFragment = getFavFragment(); Fragment hotWeiboFragment = getHotWeiboViewPagerFragment(); Fragment hotHuatiFragment = getHotHuaTiViewPagerFragment(); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); if (!timeLineFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, timeLineFragment, MainTimeLineFragment.class.getName()); fragmentTransaction.hide(timeLineFragment); } if (!favFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, favFragment, MyFavListFragment.class.getName()); fragmentTransaction.hide(favFragment); } if (!hotWeiboFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, hotWeiboFragment, HotWeiboViewPagerFragment.class.getName()); fragmentTransaction.hide(hotWeiboFragment); } if (!hotHuatiFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, hotHuatiFragment, HotHuaTiViewPagerFragment.class.getName()); fragmentTransaction.hide(hotHuatiFragment); } if (!fragmentTransaction.isEmpty()) { fragmentTransaction.commit(); getSupportFragmentManager().executePendingTransactions(); } }
Example 17
Source File: MainActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first fragment if (findViewById(R.id.frag_container) == null ) { //landscape or large mode. both fragments will be displayed on the screen. Log.d("fd3", "two pane"); TwoPane = true; } else { //protrait mode Log.d("fd3", "one pane"); //get them if they already exist else create them. firstFragment = (titlefrag) getSupportFragmentManager().findFragmentByTag("first"); if (firstFragment == null) { firstFragment = new titlefrag(); } secondFragment = (textFrag) getSupportFragmentManager().findFragmentByTag("Second"); if (secondFragment == null) { secondFragment = new textFrag(); Bundle args = new Bundle(); args.putInt("position", 0); secondFragment.setArguments(args); } FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(firstFragment); remove.remove(secondFragment); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // return; // } // In case this activity was started with special instructions from an Intent, // pass the Intent's extras to the fragment as arguments // firstFragment.setArguments(getIntent().getExtras()); // Add the fragment to the 'fragment_container' FrameLayout fragmentManager.beginTransaction().replace(R.id.frag_container, firstFragment, "first").commit(); } }
Example 18
Source File: ActionbarActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_actionbar); //turn on up button getSupportActionBar().setDisplayHomeAsUpEnabled(true); FragmentManager fragmentManager = getSupportFragmentManager(); if (savedInstanceState != null) { one = (PageFragment) fragmentManager.getFragment(savedInstanceState, "ONE"); two = (PageFragment) fragmentManager.getFragment(savedInstanceState, "TWO"); three = (PageFragment) fragmentManager.getFragment(savedInstanceState, "THREE"); four = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FOUR"); five = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FIVE"); //since survived, need to clean up or I can't add them to the pagers adapter again. FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(one); remove.remove(two); remove.remove(three); remove.remove(four); remove.remove(five); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } } else { one = PageFragment.create(1); two = PageFragment.create(2); three = PageFragment.create(3); four = PageFragment.create(4); five = PageFragment.create(5); } viewPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new myFragmentPagerAdapter(5); viewPager.setAdapter(mPagerAdapter); //viewPager.setCurrentItem(2); //we need to know when a page has changed, so we can change/fix the next/previous/finish buttons viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { supportInvalidateOptionsMenu(); } }); }
Example 19
Source File: MainActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //getSupportFragmentManager().beginTransaction().add(R.id.frag_container, firstFragment).commit(); //first find the 3 fragments, if create them as needed. //Remember fragments can survive the restart of an activity on orientation change. FragmentManager fragmentManager = getSupportFragmentManager(); if (savedInstanceState != null) { leftfrag = (FragLeft) fragmentManager.getFragment(savedInstanceState, "LEFT"); midfrag = (FragMid) fragmentManager.getFragment(savedInstanceState,"MIDDLE"); rightfrag = (FragRight) fragmentManager.getFragment(savedInstanceState,"RIGHT"); //since survived, remove them from the fragment manager, so don't double add them. FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(leftfrag); remove.remove(midfrag); remove.remove(rightfrag); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } } else { leftfrag = new FragLeft(); midfrag = new FragMid(); rightfrag = new FragRight(); } viewPager = (ViewPager) findViewById(R.id.pager); if (viewPager != null) { //in portrait mode viewPager.setAdapter(new ThreeFragmentPagerAdapter(fragmentManager)); } else { //in landscape mode fragmentManager.beginTransaction() .add(R.id.frag_left, leftfrag, "LEFT") .add(R.id.frag_mid, midfrag, "MIDDLE") .add(R.id.frag_right, rightfrag, "RIGHT") .commit(); } }
Example 20
Source File: ActionbarActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fragmentManager = getSupportFragmentManager(); if (savedInstanceState != null) { one = (PageFragment) fragmentManager.getFragment(savedInstanceState, "ONE"); two = (PageFragment) fragmentManager.getFragment(savedInstanceState, "TWO"); three = (PageFragment) fragmentManager.getFragment(savedInstanceState, "THREE"); four = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FOUR"); five = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FIVE"); //since survived, need to clean up or I can't add them to the pagers adapter again. FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(one); remove.remove(two); remove.remove(three); remove.remove(four); remove.remove(five); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } } else { one = PageFragment.create(1); two = PageFragment.create(2); three = PageFragment.create(3); four = PageFragment.create(4); five = PageFragment.create(5); } viewPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new myFragmentPagerAdapter(5); viewPager.setAdapter(mPagerAdapter); //viewPager.setCurrentItem(2); //we need to know when a page has changed, so we can change/fix the next/previous/finish buttons viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @SuppressLint("NewApi") @Override public void onPageSelected(int position) { // When changing pages, reset the action bar actions since they are dependent // on which page is currently active. An alternative approach is to have each // fragment expose actions itself (rather than the activity exposing actions), // but for simplicity, the activity provides the actions in this sample. if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) { //should kept this demo from force closing if run on the wrong API... I think... //Note, if below HONEYCOMB, then no buttons, because no actionbar. invalidateOptionsMenu();} } }); }