本文整理汇总了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));
}
}