本文整理汇总了Java中android.support.v4.app.Fragment.isDetached方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.isDetached方法的具体用法?Java Fragment.isDetached怎么用?Java Fragment.isDetached使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.isDetached方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: switchFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void switchFragment(@NonNull Fragment fragment, String tag) {
if (fragment.isAdded()) {
return;
}
final FragmentManager manager = getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = manager.beginTransaction();
final Fragment currentFragment = manager.findFragmentById(R.id.container);
if (currentFragment != null) {
fragmentTransaction.detach(currentFragment);
}
if (fragment.isDetached()) {
fragmentTransaction.attach(fragment);
} else {
fragmentTransaction.add(R.id.container, fragment, tag);
}
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
示例2: getItemPosition
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public int getItemPosition(Object object) {
if (object instanceof Fragment) {
final Fragment fragment = (Fragment) object;
final String tag = fragment.getTag();
if (fragment.isDetached() || tag == null) {
return POSITION_NONE;
}
int position = 0;
for (T data : mList) {
if (tag.equals(makeFragmentTag(mContainerId, getItemId(data)))) {
return position;
}
position++;
}
return POSITION_NONE;
}
return super.getItemPosition(object);
}
示例3: showDirectoryWithSelectedTab
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void showDirectoryWithSelectedTab(FileInfo fileInfo) {
Preconditions.checkNotNull(fileInfo, "fileInfo == null");
Preconditions.checkNotNull(mSelectedDirectory, "mSelectedDirectory == null");
Log.d(TAG, "showDirectoryWithSelectedTab: " + fileInfo.getName());
if (mSelectedDirectory != fileInfo) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
Fragment f = mFragmentManager.findFragmentByTag(mSelectedDirectory.getAbsolutePath());
if (f != null && !f.isDetached()) {
ft.detach(f);
}
mSelectedDirectory = fileInfo;
f = mFragmentManager.findFragmentByTag(fileInfo.getAbsolutePath());
if (f == null) {
f = FileInfosFragment.newInstance(fileInfo.getAbsolutePath());
ft.add(R.id.contentFrame, f, fileInfo.getAbsolutePath());
} else {
ft.attach(f);
}
ft.commit();
}
}
示例4: onBackPressed
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onBackPressed()
{
if (mFragmentManager.findFragmentByTag("home").isDetached())
{
fragStuff.setFragmentByTag("home");
for (Fragment fragment : mFragmentManager.getFragments())
{
if (fragment != null && !fragment.isDetached() && fragment instanceof ChatFragment)
{
if (((ChatFragment) fragment).getmSlidingMenu().isMenuShowing())
{
((ChatFragment) fragment).getmSlidingMenu().hideMenu(true);
}
}
}
if (mChatroomSlidingMenu.isMenuShowing())
{
mChatroomSlidingMenu.hideMenu(true);
}
}
else if (mChatroomSlidingMenu.isMenuShowing())
{
mChatroomSlidingMenu.hideMenu(true);
}
else
{
super.onBackPressed();
}
}
示例5: reattachRemovedFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void reattachRemovedFragment(Fragment fragment, FragmentTransaction fragmentTransaction, Path key, int containerId) {
if(fragment == null) {
fragment = key.createFragment();
}
if(!fragment.isAdded() || (fragment.isDetached() || fragment.getView() == null)) {
fragmentTransaction.add(containerId, fragment, key.getFragmentTag());
}
}
示例6: removeToDetachFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private Fragment removeToDetachFragment(StateChange stateChange, Path key) {
Fragment fragment = fragmentManager.findFragmentByTag(key.getFragmentTag());
if(fragment != null && (fragment.isDetached() || fragment.getView() == null)) {
FragmentTransaction fragmentTransaction = beginFragmentTransaction(stateChange);
Fragment.SavedState savedState = fragmentManager.saveFragmentInstanceState(fragment);
fragmentTransaction.remove(fragment);
fragmentTransaction.commitNow();
fragment.setInitialSavedState(savedState);
}
return fragment;
}
示例7: showDirectoryWithBackPressed
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void showDirectoryWithBackPressed() {
Preconditions.checkNotNull(mSelectedDirectory, "mSelectedDirectory == null");
Preconditions.checkArgument(mDirectories.contains(mSelectedDirectory),
"mDirectories not contain:" + mSelectedDirectory.getAbsolutePath());
final int selectedPosition = mDirectories.indexOf(mSelectedDirectory);
if (selectedPosition == 0) {
finish();
} else {
FragmentTransaction ft = mFragmentManager.beginTransaction();
Fragment f = mFragmentManager.findFragmentByTag(mSelectedDirectory.getAbsolutePath());
if (f != null && !f.isDetached()) {
ft.detach(f);
}
int previousPosition = selectedPosition - 1;
FileInfo previous = mSelectedDirectory = mDirectories.get(previousPosition);
f = mFragmentManager.findFragmentByTag(previous.getAbsolutePath());
if (f == null) {
f = FileInfosFragment.newInstance(previous.getAbsolutePath());
ft.add(R.id.contentFrame, f, previous.getAbsolutePath());
} else {
ft.attach(f);
}
ft.commit();
Message msg = mMyHandler.obtainMessage();
msg.arg1 = previousPosition;
mMyHandler.sendMessageDelayed(msg, 100L);
}
}
示例8: showChart
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private void showChart() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(CHART_FRAGMENT);
if (fragment != null && !fragment.isDetached() && fragment.getId() != R.id.chart_dual) {
return;
}
openSinglePaneChartFragment();
}
示例9: setFragmentByTag
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* Open a chat using its tag
*
* @param tag the chat's fragment tag (should be its URL)
*/
public void setFragmentByTag(String tag)
{
Log.e("TAG", tag);
if (mainActivity.mFragmentManager.getFragments() != null)
{
for (Fragment fragment : mainActivity.mFragmentManager.getFragments())
{
if (fragment != null && !fragment.isDetached())
{
mainActivity.mFragmentManager.beginTransaction().detach(fragment).commit();
}
}
Fragment fragToAttach = mainActivity.mFragmentManager.findFragmentByTag(tag);
if (fragToAttach != null)
{
if (tag.equals("home"))
{
mainActivity.mFragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out).attach(fragToAttach).commit();
mainActivity.mCurrentUsers_SlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
((HomeFragment) fragToAttach).hueTest();
}
else
{
if (mainActivity.mFragmentManager.findFragmentByTag("home").isDetached())
{
mainActivity.mFragmentManager.beginTransaction().attach(fragToAttach).commit();
}
else
{
mainActivity.mFragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out).attach(fragToAttach).commit();
}
mainActivity.mCurrentUsers_SlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
}
}
else
{
Log.e("TAG", tag);
}
}
}