本文整理汇总了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;
}
}
示例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;
}
示例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);
}
};
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
});
}
示例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();
}
示例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);
}
示例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();
}
}
示例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();
}
}
}
}
示例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);
}
示例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();
}
示例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");
}
示例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");
}