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