當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。