Java Code Examples for android.support.v4.app.Fragment

The following are top voted examples for showing how to use android.support.v4.app.Fragment. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: mobile-dashboard   File: TabsPagerAdapter.java   View source code 6 votes vote down vote up
@Override
public Fragment getItem(int index) {

    switch (index) {
        case 0:
            // System notifications fragment activity
            return new SystemFragment();
        case 1:
            // Application notifications fragment activity
            return new AppsFragment();
        case 2:
            // Stats fragment activity
            return new StatsFragment();
        case 3:
            // Settings fragment activity
            return new StatsFragment();
    }

    return null;
}
 
Example 2
Project: RecyclerViewPreferences   File: SettingsFragment.java   View source code 6 votes vote down vote up
public void setUseExpandableHeaders(boolean enabled) {
    if (isViewPager()) {
        Collection<Fragment> fragments = mPagerAdapter.getAllCachedFragments();
        for (Fragment f : fragments) {
            ((SettingsFragment) f).setUseExpandableHeaders(enabled);
        }
    } else {
        setup.setUseExpandableHeaders(enabled);
        getArguments().putParcelable("setup", setup);
        if (mItems != null) {
            if (!enabled) {
                FastAdapterUtil.expand(mFastItemAdapter);
            }
            SettingsUtil.updateExpandableHeaders(mItems, enabled);
            SettingsUtil.setExpandedState(mItems, true);
            mFastItemAdapter.notifyAdapterDataSetChanged();
        }
    }
}
 
Example 3
Project: PictureShow   File: PhotoViewFragment.java   View source code 6 votes vote down vote up
public static Fragment newInstance(Cursor c, int position) {
    final Fragment f = new PhotoViewFragment();
    final Bundle b = new Bundle();

    int photoID = c.getInt(0);
    b.putInt(MediaSetUtils.PHOTO_ID, photoID);

    String path = c.getString(1);
    b.putString(MediaSetUtils.PHOTO_PATH, path);

    String type = c.getString(2);
    b.putInt(TYPE, type == null ? MediaSetUtils.TYPE_IMAGE :
            (type.startsWith("video") ? MediaSetUtils.TYPE_VIDEO : MediaSetUtils.TYPE_IMAGE));

    b.putInt(CURRENT_POSITION, position);
    f.setArguments(b);
    return f;
}
 
Example 4
Project: sealtalk-android-master   File: RecognizePlugin.java   View source code 6 votes vote down vote up
@Override
public void onClick(Fragment currentFragment, final RongExtension extension) {
    String[] permissions = {Manifest.permission.RECORD_AUDIO};
    if (!PermissionCheckUtil.requestPermissions(currentFragment, permissions)) {
        return;
    }
    if (SpeechUtility.getUtility() == null) {
        SpeechUtility.createUtility(extension.getContext().getApplicationContext(), SpeechConstant.APPID + "=581f2927"); //初始化
    }
    recognizerView = new RecognizerView(extension.getContext());
    recognizerView.setResultCallBack(new IRecognizedResult() {
        @Override
        public void onResult(String data) {
            Editable editable = extension.getInputEditText().getText();
            String str = editable.toString() + data;
            extension.getInputEditText().setText(str);
            extension.getInputEditText().setSelection(str.length());
        }

        @Override
        public void onClearClick() {
            extension.getInputEditText().setText("");
        }
    });
    extension.addPluginPager(recognizerView);
}
 
Example 5
Project: CricKotlin   File: AppInjector.java   View source code 6 votes vote down vote up
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example 6
Project: boohee_v5.6   File: CookSearchActivity.java   View source code 6 votes vote down vote up
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (!ViewUtils.isFastDoubleClick() && this.activity != null) {
        switch (parent.getId()) {
            case R.id.lv_result:
                Fragment addMaterialFragment = AddMaterialFragment.newInstance((
                        (FoodWithUnit) this.mResultAdapter.getItem(position)).code);
                FragmentTransaction transaction = getSupportFragmentManager()
                        .beginTransaction();
                transaction.add(addMaterialFragment, "addMaterialFragment");
                transaction.commitAllowingStateLoss();
                return;
            default:
                return;
        }
    }
}
 
Example 7
Project: XinFramework   File: SupportHelper.java   View source code 6 votes vote down vote up
public static ISupportFragment getTopFragment(FragmentManager fragmentManager, int containerId) {
    List<Fragment> fragmentList = FragmentationHack.getActiveFragments(fragmentManager);
    if (fragmentList == null) return null;

    for (int i = fragmentList.size() - 1; i >= 0; i--) {
        Fragment fragment = fragmentList.get(i);
        if (fragment instanceof ISupportFragment) {
            ISupportFragment iFragment = (ISupportFragment) fragment;
            if (containerId == 0) return iFragment;

            if (containerId == iFragment.getSupportDelegate().mContainerId) {
                return iFragment;
            }
        }
    }
    return null;
}
 
Example 8
Project: USLI2018   File: AppFragmentPagerAdapter.java   View source code 6 votes vote down vote up
/**
 * Returns a fragment for the current tab
 * @param position
 * @return a Fragment
 */
@Override
public Fragment getItem(int position) {
    Fragment fragment = null;
    switch(position) {
        case RADIO_FRAGMENT:
            fragment = new RadioFragment();
            break;
        case SENSORS_FRAGMENT:
            fragment = new SensorFragment();
            break;
        case TRACKING_FRAGMENT:
            fragment = new TrackingFragment();
            break;
    }
    return fragment;
}
 
Example 9
Project: AndroidProgramming3e   File: SingleFragmentActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
}
 
Example 10
Project: Android-UtilCode   File: FragmentUtils.java   View source code 5 votes vote down vote up
/**
 * 设置背景色
 *
 * @param fragment fragment
 * @param color    背景色
 */
public static void setBackgroundColor(@NonNull Fragment fragment, @ColorInt int color) {
    View view = fragment.getView();
    if (view != null) {
        view.setBackgroundColor(color);
    }
}
 
Example 11
Project: Orin   File: CustomFragmentStatePagerAdapter.java   View source code 5 votes vote down vote up
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment) object;
    if (fragment != mCurrentPrimaryItem) {
        if (mCurrentPrimaryItem != null) {
            mCurrentPrimaryItem.setMenuVisibility(false);
            mCurrentPrimaryItem.setUserVisibleHint(false);
        }
        if (fragment != null) {
            fragment.setMenuVisibility(true);
            fragment.setUserVisibleHint(true);
        }
        mCurrentPrimaryItem = fragment;
    }
}
 
Example 12
Project: BuddyBook   File: MainActivity.java   View source code 5 votes vote down vote up
public void refreshCurrentFragment(){
    Fragment frag = getSupportFragmentManager().findFragmentById(R.id.fragment_main_container);

    if(frag instanceof BookGridFragment){
        ((BookGridFragment) frag).refresh();
    }else if(frag instanceof ViewPagerFragment){
        ((ViewPagerFragment) frag).refresh();
    }
}
 
Example 13
Project: AndroidDigIn   File: MDMainActivity.java   View source code 5 votes vote down vote up
private void showFragmentByReplace(Fragment fragment, boolean addToBackStack){
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (mCurrentFragment != null) {
        fragmentTransaction.remove(mCurrentFragment);
        mCurrentFragment = null;
    }
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.replace(R.id.content_container,fragment).commit();
    mCurrentFragment = fragment;
}
 
Example 14
Project: HeroVideo-master   File: MainActivity.java   View source code 5 votes vote down vote up
/**
     * 初始化Fragments
     */
    private void initFragments()
    {

        mHomePageFragment = HomePageFragment.newInstance();
//        IFavoritesFragment mFavoritesFragment = IFavoritesFragment.newInstance();
//        HistoryFragment mHistoryFragment = HistoryFragment.newInstance();
//        AttentionPeopleFragment mAttentionPeopleFragment = AttentionPeopleFragment.newInstance();
//        ConsumeHistoryFragment mConsumeHistoryFragment = ConsumeHistoryFragment.newInstance();
//        SettingFragment mSettingFragment = SettingFragment.newInstance();

//        fragments = new Fragment[]{
//                mHomePageFragment,
//                mFavoritesFragment,
//                mHistoryFragment,
//                mAttentionPeopleFragment,
//                mConsumeHistoryFragment,
//                mSettingFragment
//        };
        fragments = new Fragment[]{mHomePageFragment};

        // 添加显示第一个fragment
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container, mHomePageFragment)
                .show(mHomePageFragment).commit();
    }
 
Example 15
Project: Android-UtilCode   File: FragmentUtils.java   View source code 5 votes vote down vote up
/**
 * 显示fragment
 *
 * @param fragment fragment
 * @return show的Fragment
 */
public static Fragment showFragment(@NonNull Fragment fragment) {
    Args args = getArgs(fragment);
    if (args != null) {
        putArgs(fragment, new Args(args.id, false, args.isAddStack));
    }
    return operateFragment(fragment.getFragmentManager(), null, fragment, TYPE_SHOW_FRAGMENT);
}
 
Example 16
Project: Responder-Android   File: MainActivity.java   View source code 5 votes vote down vote up
public void refreshFragment() {
	FragmentTransaction ft = mFragmentManager.beginTransaction();
	Fragment currentFragment = mFragmentManager.findFragmentById(R.id.content_frame);
	if (currentFragment.getClass().equals(MapFragment.class)) {
		((MapFragment) currentFragment).insertMarkersAndCenter();
	} else {
		ft.detach(currentFragment).attach(currentFragment).commit();
	}
}
 
Example 17
Project: oma-riista-android   File: MainActivity.java   View source code 5 votes vote down vote up
private void displayMorePopupMenu() {
    PopupMenu popupMenu = new PopupMenu(MainActivity.this, mBottomNavigationView.getTabWithId(R.id.menu_more));
    popupMenu.getMenuInflater().inflate(R.menu.main_navigation_more, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Fragment innerFragment = null;

            switch (item.getItemId()) {
                case R.id.menu_contact:
                    innerFragment = ContactDetailsFragment.newInstance();
                    break;
                case R.id.menu_settings:
                    innerFragment = SettingsFragment.newInstance();
                    break;
                case R.id.menu_magazine:
                    Intent intent = new Intent(MainActivity.this, MagazineActivity.class);
                    if (AppPreferences.LANGUAGE_CODE_SV.equalsIgnoreCase(AppPreferences.getLanguageCodeSetting(MainActivity.this))) {
                        intent.putExtra(MagazineActivity.EXTRA_URL, AppConfig.MAGAZINE_URL_SV);
                    }
                    else {
                        intent.putExtra(MagazineActivity.EXTRA_URL, AppConfig.MAGAZINE_URL_FI);
                    }
                    startActivity(intent);
                    break;
                case R.id.menu_logout:
                    confirmLogout();
                    break;
            }

            replacePageFragment(innerFragment);
            return true;
        }
    });

    popupMenu.setGravity(Gravity.RIGHT);
    popupMenu.show();
}
 
Example 18
Project: Aurora   File: FragmentLifecycle.java   View source code 5 votes vote down vote up
@Override
public void onFragmentViewCreated(FragmentManager fm, Fragment f, View v, Bundle savedInstanceState) {
    Timber.w(f.toString() + " - onFragmentViewCreated");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onCreateView(v, savedInstanceState);
    }
}
 
Example 19
Project: AndroidUtilCode-master   File: FragmentUtils.java   View source code 5 votes vote down vote up
/**
 * 设置背景色
 *
 * @param fragment fragment
 * @param color    背景色
 */
public static void setBackgroundColor(@NonNull Fragment fragment, @ColorInt int color) {
    View view = fragment.getView();
    if (view != null) {
        view.setBackgroundColor(color);
    }
}
 
Example 20
Project: MVPArmsTest1   File: ActivityLifecycle.java   View source code 5 votes vote down vote up
@Override
public void onFragmentViewDestroyed(FragmentManager fm, Fragment f) {
    super.onFragmentViewDestroyed(fm, f);
    Timber.w(f.toString() +"onFragmentViewDestroyed");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onDestroyView();
    }
}
 
Example 21
Project: MoligyMvpArms   File: FragmentLifecycle.java   View source code 5 votes vote down vote up
@Override
public void onFragmentDetached(FragmentManager fm, Fragment f) {
    Timber.w(f.toString() + " - onFragmentDetached");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onDetach();
        f.getArguments().clear();
    }
}
 
Example 22
Project: AdaptiveTableLayout   File: PermissionHelper.java   View source code 5 votes vote down vote up
/**
 * @return true if all permissions is granted
 */
public static boolean checkOrRequest(@NonNull Fragment fragment, int requestCode, String... permissions) {
    if (!check(fragment.getContext(), permissions)) {
        fragment.requestPermissions(permissions, requestCode);
        return false;
    } else return true;
}
 
Example 23
Project: EasyEmoji   File: EmojiStylesFragment.java   View source code 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
    EmojiFragment fragment = mEmojiStyleWrapperManager.getFragment(position);
    if(mEmojiconEditText != null){
        fragment.setOnEmojiconClickedListener(EmojiStylesFragment.this);
    }
    return fragment;
}
 
Example 24
Project: androidadvanced   File: MainActivity.java   View source code 5 votes vote down vote up
private void setupAdapter() {
    Fragment[] fragments = new Fragment[]{new ImagesFragment(), new HashtagsFragment()};
    String[] titles = new String[]{getString(R.string.main_header_images), getString(R.string.main_header_hashtags)};
    MainSectionsPagerAdapter adapter =
                        new MainSectionsPagerAdapter(getSupportFragmentManager(),
                                                     titles, fragments);
    viewPager.setAdapter(adapter);
    tabs.setupWithViewPager(viewPager);
}
 
Example 25
Project: FinalProject   File: DiscoverActivityFragmentPagerAdapter.java   View source code 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0: // Fragment # 0 - This will show latest discover fragment
            return DiscoverLatestFragment.newInstance(1);
        case 1: // Fragment # 0 - This will popular discover fragment
            return DiscoverTrendingFragment.newInstance(2);
        case 2: // Fragment # 1 - This will show Featured
            return DiscoverFeaturedFragment.newInstance(0);
        default:
            return null;
    }
}
 
Example 26
Project: WatchIt   File: WatchLaterActivity.java   View source code 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0:
            return MoviesWatchLaterFragment.newInstance();
        case 1:
            return TvSeriesWatchLaterFragment.newInstance();
        default:
            return null;
    }
}
 
Example 27
Project: BuddyBook   File: MainActivity.java   View source code 5 votes vote down vote up
public void checkTabLayout(){
    Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_main_container);

    if (currentFragment instanceof ViewPagerFragment) {
        mTabLayout.setVisibility(View.VISIBLE);
        mTabLayout.setupWithViewPager(((ViewPagerFragment) currentFragment).getViewPager());
        setupTabIcons(((ViewPagerFragment) currentFragment).getTypeFragment());
    }else{
        mTabLayout.setVisibility(View.GONE);
    }
}
 
Example 28
Project: CXJPadProject   File: BFragment.java   View source code 5 votes vote down vote up
public void showChildFragment(@IdRes int id_content, Fragment fragment1, Fragment fragment2) {
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    if (!fragment1.isAdded()) {
        ft.add(id_content, fragment1);
    }
    if (!fragment2.isAdded()) {
        ft.add(id_content, fragment2);
    }

    ft.hide(fragment1).show(fragment2);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 29
Project: Hotspot-master-devp   File: HotspotMainActivity.java   View source code 5 votes vote down vote up
private void initIndicator() {
    mProjectionFragment = ProjectionFragment.newInstance();
    mSpecialFragment = SpecialFragment.newInstance();
    mTitleList.add("投屏");
    mTitleList.add("创富");
    mTitleList.add("生活");
    mTitleList.add("专题");
    mFragmentList.add(mProjectionFragment);
    mFragmentList.add(WealthLifeFragment.getInstance(101));
    mFragmentList.add(WealthLifeFragment.getInstance(102));
    mFragmentList.add(mSpecialFragment);

    Bundle bundle = new Bundle();
    bundle.putString("title", "专题");
    mPagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
    mPagerAdapter.setData(mFragmentList,mTitleList);
    mViewPager.setAdapter(mPagerAdapter);
    mTabLayout.setViewPager(mViewPager);
    mViewPager.setOffscreenPageLimit(3);

    List<Fragment> fragmentList = new ArrayList<>();
    List<String> titleList = new ArrayList<>();
    titleList.add("创富");
    titleList.add("生活");
    titleList.add("专题");
    fragmentList.add(WealthLifeFragment.getInstance(101));
    fragmentList.add(WealthLifeFragment.getInstance(102));
    fragmentList.add(SpecialFragment.newInstance());
    mShadePagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
    mShadePagerAdapter.setData(fragmentList,titleList);
    mShadeViewPager.setAdapter(mShadePagerAdapter);
    mShadeTabContainer.setViewPager(mShadeViewPager);
    mShadeViewPager.setOffscreenPageLimit(0);
}
 
Example 30
Project: quickblox-android   File: PreviewFragment.java   View source code 5 votes vote down vote up
public static Fragment newInstance(int imageResourceId) {
    PreviewFragment previewFragment = new PreviewFragment();
    Bundle bundle = new Bundle();
    bundle.putInt(PREVIEW_IMAGE, imageResourceId);
    previewFragment.setArguments(bundle);
    return previewFragment;

}
 
Example 31
Project: SampleAppArch   File: PagerActivity.java   View source code 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
    switch (position)
    {
        case FRAGMENT_A_POS :
            return BlankFragmentA.newInstance();
        case FRAGMENT_B_POS:
            return BlankFragmentB.newInstance();
        default:
            break;
    }
    return null;
}
 
Example 32
Project: android-advanced-light   File: CoordinatorLayoutActivity.java   View source code 5 votes vote down vote up
private void initViewPager() {

        mTabLayout = (TabLayout) findViewById(R.id.tabs);
        List<String> titles = new ArrayList<>();
        titles.add("精选");
        titles.add("体育");
        titles.add("巴萨");
        titles.add("购物");
        titles.add("明星");
        titles.add("视频");
        titles.add("健康");
        titles.add("励志");
        titles.add("图文");
        titles.add("本地");
        titles.add("动漫");
        titles.add("搞笑");
        titles.add("精选");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(new ListFragment());
        }
        FragmentAdapter mFragmentAdapteradapter =
                new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        mViewPager.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        mTabLayout.setupWithViewPager(mViewPager);
        //给TabLayout设置适配器
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);

    }
 
Example 33
Project: API-Example-App   File: MainActivity.java   View source code 5 votes vote down vote up
/**
 * Send the callback information from the {@link SaiyListener} to the relevant
 * fragment
 *
 * @param error     one of {@link Defaults.ERROR}
 * @param requestId the unique request id sent with each API request
 */
@Override
public void onError(final Defaults.ERROR error, final String requestId) {

    final int currentTag = Integer.parseInt(getSupportFragmentManager().findFragmentById(
            R.id.fragmentContent).getTag());

    Fragment fragment;

    switch (currentTag) {

        case INDEX_FRAGMENT_DEMO_BASIC:
            fragment = getSupportFragmentManager()
                    .findFragmentByTag(String.valueOf(INDEX_FRAGMENT_DEMO_BASIC));

            if (fragment != null) {
                ((FragmentDemoBasic) fragment).onError(error, requestId);
            }
            break;
        case INDEX_FRAGMENT_DEMO_INTERACTION:
            fragment = getSupportFragmentManager()
                    .findFragmentByTag(String.valueOf(INDEX_FRAGMENT_DEMO_INTERACTION));
            if (fragment != null) {
                ((FragmentDemoInteraction) fragment).onError(error, requestId);
            }
            break;
    }
}
 
Example 34
Project: BlackList   File: MainActivity.java   View source code 5 votes vote down vote up
private void switchFragment(Fragment fragment, Bundle arguments) {
    // replace the current showed fragment
    Fragment current = getSupportFragmentManager().findFragmentByTag(CURRENT_FRAGMENT);
    if (current != fragment) {
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().
                replace(R.id.frame_layout, fragment, CURRENT_FRAGMENT).commit();
    }
}
 
Example 35
Project: Ghost-Android   File: LoginActivity.java   View source code 5 votes vote down vote up
@Override
public void onGhostV0Error() {
    Fragment fragment = GhostV0ErrorFragment.newInstance();
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .addToBackStack(null)
            .commit();
}
 
Example 36
Project: exciting-app   File: VoiceMainActivity.java   View source code 5 votes vote down vote up
private void setupMainFragment(Bundle savedInstanceState) {
    Fragment menuFragment;
    if (savedInstanceState != null) {
        menuFragment = getSupportFragmentManager().findFragmentByTag(FRG_VOICE_MENU);
        if (menuFragment == null) {
            menuFragment = TheHostVoiceMenuFragment.newInstance();
            getSupportFragmentManager().beginTransaction().add(R.id.fl_menu, menuFragment, FRG_VOICE_MENU).commit();
        }
        getSupportFragmentManager().beginTransaction().show(menuFragment).commit();
    } else {
        menuFragment = TheHostVoiceMenuFragment.newInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.fl_menu, menuFragment, FRG_VOICE_MENU).commit();
        getSupportFragmentManager().beginTransaction().show(menuFragment).commitAllowingStateLoss();
    }
}
 
Example 37
Project: letv   File: LetvBaseActivity.java   View source code 5 votes vote down vote up
public void removeFragment(Fragment fragment) {
    if (fragment != null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.remove(fragment);
        try {
            transaction.commitAllowingStateLoss();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 38
Project: MVPArms_Fragment-fragment   File: FragmentUtils.java   View source code 5 votes vote down vote up
/**
 * 替换fragment
 *
 * @param srcFragment   源fragment
 * @param destFragment  目标fragment
 * @param isAddStack    是否入回退栈
 * @param sharedElement 共享元素
 * @return 目标fragment
 */
public static Fragment replaceFragment(@NonNull Fragment srcFragment,
                                       @NonNull Fragment destFragment,
                                       boolean isAddStack,
                                       SharedElement... sharedElement) {
    if (srcFragment.getArguments() == null)
        return null;
    int containerId = srcFragment.getArguments().getInt(ARGS_ID);
    if (containerId == 0)
        return null;
    return replaceFragment(srcFragment.getFragmentManager(), destFragment, containerId, isAddStack, sharedElement);
}
 
Example 39
Project: MusicX-music-player   File: PagerAdapter.java   View source code 5 votes vote down vote up
@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;
}
 
Example 40
Project: Hotspot-master-devp   File: GlideImageLoader.java   View source code 5 votes vote down vote up
public  void loadImageWithNoAnimate(Fragment fragment, String imgPath, ImageView imageView, int placeholderResId, int failedResId) {
    Glide.with(fragment)
            .load(imgPath)
            .placeholder(placeholderResId)
            .error(failedResId)
            .dontAnimate()
            .crossFade()
            .into(imageView);
}