本文整理匯總了Java中android.support.v4.app.Fragment.isAdded方法的典型用法代碼示例。如果您正苦於以下問題:Java Fragment.isAdded方法的具體用法?Java Fragment.isAdded怎麽用?Java Fragment.isAdded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.isAdded方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkHide
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 切換fragment(隱藏)
*/
protected final void checkHide(int viewId, int showIndex) {
List allFragment = bindFragment();
hideAllFrag(showIndex);
FragmentTransaction b = getSupportFragmentManager().beginTransaction();
if (showIndex >= allFragment.size()) {
Logger.e("showIndex >= allFragment.size():showIndex=" + showIndex + ",allFragment.size()=" + allFragment.size());
return;
}
Fragment fragment = (Fragment) allFragment.get(showIndex);
if (!fragment.isAdded()) {
b.add(viewId, fragment);
}
b.show(fragment);
b.commit();
}
示例2: switchFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 轉換 Fragment
* 首先當前存在 Fragment,並且當前 Fragment 不是要轉換的 Fragment ,避免重複操作
* <p>
* 被替換的 Fragment 隻是被覆蓋,並沒被銷毀
*
* @param fragment 需要轉換的Fargment
*/
public void switchFragment(Fragment fragment) {
if (mCurrentFragment == null
|| !fragment.getClass().getName().equals(mCurrentFragment.getClass().getName())) {
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in,
android.R.anim.fade_out);
if (!fragment.isAdded()) { // 檢查 fragment 是否被添加
// 隱藏當前 mCurrentFragment,add fragment 到 Activity 中
fragmentTransaction
.hide(mCurrentFragment)
.add(getFragmentContainerId(), fragment)
.commit();
mCurrentFragment = fragment;
} else {
// 隱藏當前 mCurrentFragment,顯示 fragment
fragmentTransaction
.hide(mCurrentFragment)
.show(fragment)
.commit();
mCurrentFragment = fragment;
}
}
}
示例3: changeView
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void changeView(int position) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
Fragment fragment = mFragments.get(position);
if (fragment.isAdded()) {
transaction.show(fragment);
} else {
transaction.add(R.id.sticky_container, fragment);
mVisibleFragments.add(fragment);
}
for (Fragment fragment1 : mVisibleFragments) {
if (fragment1 != fragment) {
if (fragment1.isVisible()) {
transaction.hide(fragment1);
transaction.addToBackStack(null);
}
}
}
transaction.commit();
}
示例4: switchFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 轉換Fragment
* 首先當前存在Fragment,並且當前Fragment不是要轉換的Fragment,避免重複操作
* @param fragment 需要轉換的Fargment
*/
public void switchFragment(Fragment fragment) {
if (mCurrentFragment == null
|| !fragment.getClass().getName().equals(mCurrentFragment.getClass().getName())) {
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in,
android.R.anim.fade_out);
if (!fragment.isAdded()) { // 檢查 fragment 是否被添加
// 隱藏當前 mCurrentFragment,add fragment 到 Activity 中
fragmentTransaction
.hide(mCurrentFragment)
.add(getFragmentContainerId(), fragment)
.commit();
mCurrentFragment = fragment;
} else {
// 隱藏當前 mCurrentFragment,顯示 fragment
fragmentTransaction
.hide(mCurrentFragment)
.show(fragment)
.commit();
mCurrentFragment = fragment;
}
}
}
示例5: switchFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 轉換Fragment
* 首先當前存在Fragment,並且當前Fragment不是要轉換的Fragment,避免重複操作
*
* @param fragment 需要轉換的Fargment
*/
public void switchFragment(Fragment fragment) {
if (mCurrentFragment == null
|| !fragment.getClass().getName().equals(mCurrentFragment.getClass().getName())) {
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in,
android.R.anim.fade_out);
if (!fragment.isAdded()) { // 檢查 fragment 是否被添加
// 隱藏當前 mCurrentFragment,add fragment 到 Activity 中
fragmentTransaction
.hide(mCurrentFragment)
.add(getFragmentContainerId(), fragment)
.commit();
mCurrentFragment = fragment;
} else {
// 隱藏當前 mCurrentFragment,顯示 fragment
fragmentTransaction
.hide(mCurrentFragment)
.show(fragment)
.commit();
mCurrentFragment = fragment;
}
}
}
示例6: showChildFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
public void showChildFragment(@IdRes int id_content, Fragment fragment1, Fragment fragment2, Fragment fragment3) {
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
if (!fragment1.isAdded()) {
ft.add(id_content, fragment1);
}
if (!fragment2.isAdded()) {
ft.add(id_content, fragment2);
}
if (!fragment3.isAdded()) {
ft.add(id_content, fragment3);
}
ft.hide(fragment1);
ft.hide(fragment2);
ft.show(fragment3);
ft.addToBackStack(null);
ft.commit();
}
示例7: onCreateOptionsMenu
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_main, menu);
if (isPlaylistPage()) {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
}
Fragment currentFragment = getCurrentFragment();
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
if (Util.isLandscape(getResources())) {
gridSizeItem.setTitle(R.string.action_grid_size_land);
}
setUpGridSizeMenu(absLibraryRecyclerViewCustomGridSizeFragment, gridSizeItem.getSubMenu());
menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette());
} else {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_colored_footers);
}
colorToolbar();
}
示例8: switchContent
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 動態加載fragment
*
* @param toFragment
*/
public void switchContent(Fragment toFragment) {
if (mCurrentFrag != toFragment) {
if (!toFragment.isAdded()) {
if (mCurrentFrag != null) {
mFragmentManager
.beginTransaction()
.hide(mCurrentFrag)
.commit();
}
mFragmentManager
.beginTransaction()
.add(R.id.main_view, toFragment)
.commit();
}else {
mFragmentManager.beginTransaction().hide(mCurrentFrag).show(toFragment).commit();
}
mCurrentFrag = toFragment;
}
}
示例9: onCreateOptionsMenu
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (pager == null) return;
inflater.inflate(R.menu.menu_main, menu);
if (isPlaylistPage()) {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title);
}
Fragment currentFragment = getCurrentFragment();
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment absLibraryRecyclerViewCustomGridSizeFragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette());
menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette());
} else {
menu.removeItem(R.id.action_colored_footers);
}
Activity activity = getActivity();
if (activity == null) return;
ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
}
示例10: showFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void showFragment(Fragment fragment, String tag, Fragment previousFragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (previousFragment != null && !previousFragment.isHidden()) {
fragmentTransaction.hide(previousFragment);
}
if (fragment.isHidden() || fragment.isAdded()) {
fragmentTransaction.show(fragment);
} else {
fragmentTransaction.add(R.id.container, fragment, tag);
}
fragmentTransaction.commit();
}
示例11: gotoHello
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void gotoHello() {
Fragment f = fm.findFragmentByTag(HelloFragment.TAG);
if (f == null) {
f = HelloFragment.newInstance();
}
if (!f.isAdded()) {
fm.beginTransaction().replace(R.id.main_container, f, HelloFragment.TAG).commit();
}
}
示例12: setPrimaryItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
if (position != mLastPosition) {
if (mLastPosition >= 0) {
GlideApp.with(mLastFragment).pauseRequests();
}
Fragment current = (Fragment) object;
mLastPosition = position;
mLastFragment = current;
if (current.isAdded()) {
GlideApp.with(current).resumeRequests();
}
}
}
示例13: switchFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void switchFragment(int from, int to) {
this.mCurrentId = to;
Fragment fromFragment = mFragments.get(from);
Fragment toFragment = mFragments.get(to);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (!toFragment.isAdded()) {
ft.add(R.id.fl_fragment_container, toFragment).hide(fromFragment).commitAllowingStateLoss();
} else {
ft.show(toFragment).hide(fromFragment).commitAllowingStateLoss();
}
}
示例14: onCheckedChanged
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
for (int i = 0; i < radioGroup.getChildCount(); i++) {
if (radioGroup.getChildAt(i).getId() == checkId) {
// 即將要展示的Fragment
Fragment target = mFragmentList.get(i);
Fragment currentFragment = getCurrentFragment();
currentFragment.onPause();
FragmentTransaction fragmentTransaction = getFragmentTransaction();
if (target.isAdded()) {
target.onResume();
fragmentTransaction.show(target).hide(currentFragment);
} else {
fragmentTransaction.add(mContentId, target).show(target).hide(currentFragment);
}
fragmentTransaction.commit();
currentTab = i;
if (mFragmentToogleListener != null) {
mFragmentToogleListener.onToogleChange(target, currentTab);
}
}
}
}
示例15: showProgress
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
public static void showProgress(@NonNull final Fragment fragment, final SwipeRefreshLayout swipeRefreshLayout, boolean show) {
if (!fragment.isAdded() || swipeRefreshLayout == null) return;
if (!show) {
swipeRefreshLayout.setRefreshing(false);
return;
}
if (fragment.isResumed()) {
swipeRefreshLayout.setRefreshing(true);
} else {
swipeRefreshLayout.post(() -> swipeRefreshLayout.setRefreshing(true));
}
}