本文整理汇总了Java中android.support.v4.app.Fragment.getTag方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.getTag方法的具体用法?Java Fragment.getTag怎么用?Java Fragment.getTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.getTag方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removePage
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void removePage(int position) {
if (position >= mPageAdapter.getCount() || position < 0) {
return;
}
Fragment existingFragment = mPageAdapter.getExistingFragment(position);
if (existingFragment == null) {
if (DLog.DEBUG) DLog.d(TAG, "removePage: " + "null page " + position);
return;
}
//delete in database
String filePath = existingFragment.getTag();
mFileManager.removeTabFile(filePath);
//remove page
mPageAdapter.remove(position);
invalidateTab();
Toast.makeText(mContext,
mContext.getString(R.string.closed) + " " + new File(filePath).getName(),
Toast.LENGTH_SHORT).show();
}
示例2: destroyItem
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void destroyItem(View container, int position, Object object) {
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
if (DEBUG) Log.v(TAG, "Detaching item #" + position + ": f=" + object
+ " v=" + ((Fragment)object).getView());
Fragment fragment = (Fragment) object;
String name = fragment.getTag();
if (name == null) {
// We prefer to get the name directly from the fragment, but, if the fragment is
// detached before the add transaction is committed, this could be 'null'. In
// that case, generate a name so we can still cache the fragment.
name = makeFragmentName(container.getId(), position);
}
mFragmentCache.put(name, fragment);
mCurTransaction.detach(fragment);
}
示例3: 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);
}
示例4: compatChildFragmentExitAnim
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Nullable
public Animation compatChildFragmentExitAnim(Fragment fragment) {
if ((fragment.getTag() != null && fragment.getTag().startsWith("android:switcher:") && fragment.getUserVisibleHint()) ||
(fragment.getParentFragment() != null && fragment.getParentFragment().isRemoving() && !fragment.isHidden())) {
Animation animation = new Animation() {
};
animation.setDuration(exitAnim.getDuration());
return animation;
}
return null;
}
示例5: instantiateItem
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public Object instantiateItem(ViewGroup container, int position) {
Object obj = super.instantiateItem(container, position);
if (obj instanceof Fragment) {
Fragment f = (Fragment) obj;
String tag = f.getTag();
mFragmentTags.put(position, tag);
}
return obj;
}
示例6: replaceFragment
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* Will replace de current Fragment on the layout
*
* @Param fragment The fragment to show/replace.
*/
public final void replaceFragment(Fragment fragment) {
if (fragment != null) {
String tag = fragment.getTag() != null && !fragment.getTag().isEmpty() ? fragment.getTag() : fragment.getClass().getSimpleName();
fragmentManager
.beginTransaction()
.replace(R.id.frame_layout, fragment, tag)
.commit();
}
}
示例7: getViewPagerChildFragmentAnimFixed
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Nullable
public Animation getViewPagerChildFragmentAnimFixed(Fragment fragment, boolean enter) {
if (!enter && fragment.getTag() != null && fragment.getTag().startsWith("android:switcher:")
&& fragment.getUserVisibleHint()) {
Animation animation = new Animation() {
};
animation.setDuration(exitAnim.getDuration());
return animation;
}
return null;
}
示例8: dispatchStartTransaction
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
* Dispatch the start transaction.
*/
void dispatchStartTransaction(FragmentManager fragmentManager, ISupportFragment from, ISupportFragment to, int requestCode, int launchMode, int type) {
fragmentManager = checkFragmentManager(fragmentManager, from);
if (fragmentManager == null) return;
checkNotNull(to, "toFragment == null");
if (from != null) {
if (from.getSupportDelegate().mContainerId == 0) {
Fragment fromF = (Fragment) from;
if (fromF.getTag() != null && !fromF.getTag().startsWith("android:switcher:")) {
throw new RuntimeException("Can't find container, please call loadRootFragment() first!");
}
}
bindContainerId(from.getSupportDelegate().mContainerId, to);
from = SupportHelper.getTopFragment(fragmentManager, from.getSupportDelegate().mContainerId);
}
// process SupportTransaction
String toFragmentTag = to.getClass().getName();
boolean dontAddToBackStack = false;
ArrayList<TransactionRecord.SharedElement> sharedElementList = null;
TransactionRecord transactionRecord = to.getSupportDelegate().mTransactionRecord;
if (transactionRecord != null) {
if (transactionRecord.tag != null) {
toFragmentTag = transactionRecord.tag;
}
dontAddToBackStack = transactionRecord.dontAddToBackStack;
if (transactionRecord.sharedElementList != null) {
sharedElementList = transactionRecord.sharedElementList;
// Compat SharedElement
FragmentationHack.reorderIndices(fragmentManager);
}
}
if (type == TYPE_ADD_RESULT || type == TYPE_ADD_RESULT_WITHOUT_HIDE) {
saveRequestCode((Fragment) to, requestCode);
}
if (handleLaunchMode(fragmentManager, from, to, toFragmentTag, launchMode)) return;
if (type == TYPE_ADD_WITH_POP) {
startWithPop(fragmentManager, from, to);
} else {
start(fragmentManager, from, to, toFragmentTag, dontAddToBackStack, sharedElementList, false, type);
}
}
示例9: onNavigationItemSelected
import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
String tag, url, title;
int categoryId = -1;
if (id == R.id.nav_home) {
tag = "story_home";
title = "首页";
} else {
tag = categories.get(themeIdx[id]).toString();
title = categories.get(themeIdx[id]).getName();
categoryId = categories.get(themeIdx[id]).getId();
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
// Fragment切换动画
ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
// 如果将要切换的Fragment已经存在则隐藏当前fragment并显示新fragment,否则新建fragment实例
Fragment lastFg = getSupportFragmentManager().findFragmentByTag(lastFgTag);
if (lastFg != null) {
ft.hide(lastFg);
}
Fragment nextFg = getSupportFragmentManager().findFragmentByTag(tag);
if (nextFg == null) {
nextFg = PostsFragment.newInstance(categoryId);
ft.add(R.id.story_list_fl, nextFg, tag);
} else {
ft.show(nextFg);
}
lastFgTag = nextFg.getTag();
ft.commit();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
item.setChecked(true);
setTitle(title);
return true;
}