當前位置: 首頁>>代碼示例>>Java>>正文


Java Fragment類代碼示例

本文整理匯總了Java中android.app.Fragment的典型用法代碼示例。如果您正苦於以下問題:Java Fragment類的具體用法?Java Fragment怎麽用?Java Fragment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Fragment類屬於android.app包,在下文中一共展示了Fragment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setPrimaryItem

import android.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:HueToYou,項目名稱:ChatExchange-old,代碼行數:20,代碼來源:HueFragmentPagerAdapter.java

示例2: fragmentFor

import android.app.Fragment; //導入依賴的package包/類
public static MessengerFragment fragmentFor(Activity activity) {
  FragmentManager fm = activity.getFragmentManager();
  if (fm.isDestroyed()) {
    throw new IllegalStateException("Activity already destroyed");
  }
  Fragment fragmentByTag = fm.findFragmentByTag(FRAGMENT_TAG);
  if (fragmentByTag != null && !(fragmentByTag instanceof MessengerFragment)) {
    throw new IllegalStateException("Unexpected "
        + "fragment instance was returned by FRAGMENT_TAG");
  }
  MessengerFragment fragment = (MessengerFragment) fragmentByTag;
  if (fragment == null) {
    fragment = new MessengerFragment();
    fm.beginTransaction().add(fragment, FRAGMENT_TAG)
        .commitAllowingStateLoss();
    // 接下來需要立刻通過這個 Fragment 來啟動 Activity,所以需要立刻添加到 Activity 中
    fm.executePendingTransactions();
  }
  return fragment;
}
 
開發者ID:douo,項目名稱:ActivityBuilder,代碼行數:21,代碼來源:MessengerFragment.java

示例3: getPickImageClickListener

import android.app.Fragment; //導入依賴的package包/類
public static View.OnClickListener getPickImageClickListener(final Activity activity,final Fragment fragment, final int requestCode){
    return new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pickIntent();
        }

        private void pickIntent(){
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);

            activity.startActivityFromFragment(fragment, Intent.createChooser(intent,
                    "Complete action using"), requestCode);
        }
    };
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:18,代碼來源:ChatSDKIntentClickListener.java

示例4: selectItem

import android.app.Fragment; //導入依賴的package包/類
private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new PlanetFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    // update selected item and title, then close the drawer
    mLeftDrawer.setItemChecked(position, true);
    setTitle(mContent[position]);
    mDlMain.closeDrawer(mLeftDrawer);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,代碼來源:Main2slideMenu.java

示例5: getInstanceByIndex

import android.app.Fragment; //導入依賴的package包/類
public static Fragment getInstanceByIndex(int index) {
    Fragment fragment = null;
    switch (index) {
        case R.id.firstContentTab:
            fragment = new MainFragment();
            break;
        case R.id.fangYaoTab:
            fragment = new FangFragment();
            break;
        case R.id.yaoTab:
            fragment = new YaoFragment();
            break;
        case R.id.unitTab:
            fragment = new UnitFragment();
            break;
        case R.id.settingsTab:
            fragment = new SettingsFragment();
            break;
    }
    return fragment;
}
 
開發者ID:hh-in-zhuzhou,項目名稱:ShangHanLun,代碼行數:22,代碼來源:FragmentFactory.java

示例6: showUserFragment

import android.app.Fragment; //導入依賴的package包/類
private void showUserFragment(User user){
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(USER_FRAGMENT_LABEL);
    if(prev != null){
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    UserFragment newFragment = UserFragment.newInstance(user);
    newFragment.show(ft, USER_FRAGMENT_LABEL);
}
 
開發者ID:Bartout-Team,項目名稱:Bartout,代碼行數:11,代碼來源:BartourActivity.java

示例7: execStartActivity

import android.app.Fragment; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	public ActivityResult execStartActivity(final Context who, final IBinder contextThread,
			final IBinder token, final Fragment target, final Intent intent, final int requestCode) {
		
		return execStartActivityInternal(who, intent,requestCode, new ExecStartActivityCallback() {

			@Override
			public ActivityResult execStartActivity() {
				return ActivityBridge.execStartActivity(intent,new ExecStartActivityCallback(){
					@Override
					public ActivityResult execStartActivity(Intent wrapperIntent) {
						return mBase.execStartActivity(who, contextThread, token, target, intent, requestCode);
					}
				});
//				return mBase.execStartActivity(who, contextThread, token, target, intent, requestCode);
			}
			
		});
		
	}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:21,代碼來源:InstrumentationHook.java

示例8: runCameraLiveView

import android.app.Fragment; //導入依賴的package包/類
public void runCameraLiveView() {
    final Fragment cameraView = CameraConnectionFragment.newInstance(
            new CameraConnectionFragment.ConnectionCallback() {
                @Override
                public void onPreviewSizeChosen(Size size, int rotation) {
                    MainActivity.this.onPreviewSizeChosen(size);
                }
            },
            this,
            R.layout.placerecognizer_ui,
            new Size(mImageClassifier.getImageWidth(), mImageClassifier.getImageHeight())
    );

    getFragmentManager().beginTransaction()
                    .replace(R.id.container, cameraView)
                    .commit();
}
 
開發者ID:hpi-xnor,項目名稱:android-image-classification,代碼行數:18,代碼來源:MainActivity.java

示例9: onKeyDown

import android.app.Fragment; //導入依賴的package包/類
/**
 * Temp stuff to show the rescan button that is for now hidden (not ready for prime-time)
 * (to remove once re-scan feature is published)
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode==KeyEvent.KEYCODE_DPAD_UP) {
        keyupCount++;
        if (keyupTrainStartTimeMs==0) {
            keyupTrainStartTimeMs = SystemClock.elapsedRealtime();
        }
        // Check for 5 press in less than 1 second
        if (keyupCount>4 && (SystemClock.elapsedRealtime()-keyupTrainStartTimeMs<1000)) {
            // display re-scan item
            Fragment f = getFragmentManager().findFragmentById(R.id.fragment_container);
            if (f!=null && f instanceof NetworkRootFragment) {
                ((NetworkRootFragment)f).displayRescanItem();
                Toast.makeText(this, "Displaying Re-scan item (caution it is Debug only for now)", Toast.LENGTH_SHORT).show();
            }
        }
    }
    else {
        // reset if another key is pressed
        keyupCount=0;
        keyupTrainStartTimeMs=0;
    }
    return super.onKeyDown(keyCode, event);
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:32,代碼來源:NetworkRootActivity.java

示例10: onCreate

import android.app.Fragment; //導入依賴的package包/類
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.about_us);

  final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.menu_about);
  setSupportActionBar(toolbar);
  final ActionBar ab = getSupportActionBar();
  if (ab != null) {
    ab.setDisplayHomeAsUpEnabled(true);
  }

  final FragmentManager fm = getFragmentManager();
  final Fragment fragment = fm.findFragmentById(R.id.content);
  if (fragment == null) {
    fm.beginTransaction()
        .replace(R.id.content, new AboutFragment())
        .commit();
  }
}
 
開發者ID:Elias33,項目名稱:Quran,代碼行數:22,代碼來源:AboutUsActivity.java

示例11: onBackPressed

import android.app.Fragment; //導入依賴的package包/類
@Override
public void onBackPressed() {
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.START)) {
        mDrawerLayout.closeDrawer(Gravity.START);
    } else {
        // TODO: To be improved:
        try {
            super.onBackPressed();
        } catch (IllegalStateException e){
            Fragment fragment = getFragmentManager().findFragmentByTag(MainFragment.class.getName());
            if (fragment == null) {
                fragment = new MainFragment();
            }
            if (!fragment.isAdded()) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.content_frame, fragment, MainFragment.class.getName());
                transaction.commit();
            }
        }
    }
}
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:22,代碼來源:MainActivity.java

示例12: requestSysCamera

import android.app.Fragment; //導入依賴的package包/類
/**
 * Fragment調用係統拍照
 *
 * @param fragment
 * @param requestCode
 */
public void requestSysCamera(android.support.v4.app.Fragment fragment, int requestCode) {
    requestCamaraPath = getPhotoTmpPath();
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(requestCamaraPath)));
    fragment.startActivityForResult(intent, requestCode);
}
 
開發者ID:quickhybrid,項目名稱:quickhybrid-android,代碼行數:14,代碼來源:PhotoSelector.java

示例13: reReadData

import android.app.Fragment; //導入依賴的package包/類
public void reReadData(final Activity activity){
    final ProgressBar bar = Helper.showProgressBar(activity);
    new Thread(new Runnable() {
        @Override
        public void run() {
            reReadData();
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Helper.removeFormWindow(activity, bar);
                    TabController tab = (TabController) activity;
                    for (Fragment frag : tab.fragments) {
                        if (frag instanceof MainFragment) {
                            ((MainFragment) frag).resetData(SingletonData.getInstance().getContent());
                        } else if (frag instanceof FangFragment) {
                            ((FangFragment) frag).resetData(SingletonData.getInstance().getFang());
                        }
                    }
                }
            });

        }
    }).start();
}
 
開發者ID:hh-in-zhuzhou,項目名稱:ShangHanLun,代碼行數:25,代碼來源:SingletonData.java

示例14: showEula

import android.app.Fragment; //導入依賴的package包/類
public static void showEula(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_eula");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new EulaDialog().show(ft, "dialog_eula");
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:12,代碼來源:AboutUtils.java

示例15: getItem

import android.app.Fragment; //導入依賴的package包/類
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0:
            return TutorialFragment.create(R.raw.tutorial_1, R.string.tutorial_1);
        case 1:
            return TutorialFragment.create(R.raw.tutorial_2, R.string.tutorial_2);
        case 2:
            return TutorialFragment.create(R.raw.tutorial_3, R.string.tutorial_3);
        case 3:
            return TutorialFragment.create(R.raw.tutorial_4, R.string.tutorial_4);
        case 4:
            return TutorialFragment.create(R.raw.tutorial_5, R.string.tutorial_5);
    }

    throw new UnsupportedOperationException("Each tutorial page must have its fragment");
}
 
開發者ID:nirhart,項目名稱:shortrain,代碼行數:18,代碼來源:TutorialViewPagerAdapter.java


注:本文中的android.app.Fragment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。