当前位置: 首页>>代码示例>>Java>>正文


Java Fragment类代码示例

本文整理汇总了Java中android.support.v4.app.Fragment的典型用法代码示例。如果您正苦于以下问题:Java Fragment类的具体用法?Java Fragment怎么用?Java Fragment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Fragment类属于android.support.v4.app包,在下文中一共展示了Fragment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getItem

import android.support.v4.app.Fragment; //导入依赖的package包/类
@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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-dashboard,代码行数:21,代码来源:TabsPagerAdapter.java

示例2: setUseExpandableHeaders

import android.support.v4.app.Fragment; //导入依赖的package包/类
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();
        }
    }
}
 
开发者ID:MFlisar,项目名称:RecyclerViewPreferences,代码行数:20,代码来源:SettingsFragment.java

示例3: newInstance

import android.support.v4.app.Fragment; //导入依赖的package包/类
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;
}
 
开发者ID:YuntaoWei,项目名称:PictureShow,代码行数:19,代码来源:PhotoViewFragment.java

示例4: onClick

import android.support.v4.app.Fragment; //导入依赖的package包/类
@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);
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:27,代码来源:RecognizePlugin.java

示例5: handleActivity

import android.support.v4.app.Fragment; //导入依赖的package包/类
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);
    }
}
 
开发者ID:VivekNeel,项目名称:CricKotlin,代码行数:19,代码来源:AppInjector.java

示例6: onItemClick

import android.support.v4.app.Fragment; //导入依赖的package包/类
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;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:CookSearchActivity.java

示例7: getTopFragment

import android.support.v4.app.Fragment; //导入依赖的package包/类
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;
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:18,代码来源:SupportHelper.java

示例8: getItem

import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:mike168m,项目名称:USLI2018,代码行数:22,代码来源:AppFragmentPagerAdapter.java

示例9: onCreate

import android.support.v4.app.Fragment; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:rsippl,项目名称:AndroidProgramming3e,代码行数:16,代码来源:SingleFragmentActivity.java

示例10: setBackgroundColor

import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
 * 设置背景色
 *
 * @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);
    }
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:13,代码来源:FragmentUtils.java

示例11: setPrimaryItem

import android.support.v4.app.Fragment; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:16,代码来源:CustomFragmentStatePagerAdapter.java

示例12: refreshCurrentFragment

import android.support.v4.app.Fragment; //导入依赖的package包/类
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();
    }
}
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:10,代码来源:MainActivity.java

示例13: showFragmentByReplace

import android.support.v4.app.Fragment; //导入依赖的package包/类
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;
}
 
开发者ID:halohoop,项目名称:AndroidDigIn,代码行数:13,代码来源:MDMainActivity.java

示例14: initFragments

import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
     * 初始化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();
    }
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:30,代码来源:MainActivity.java

示例15: showFragment

import android.support.v4.app.Fragment; //导入依赖的package包/类
/**
 * 显示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);
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:14,代码来源:FragmentUtils.java


注:本文中的android.support.v4.app.Fragment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。