Android Fragment - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Fragment class.

This code example shows how to use the following methods: setMenuVisibility, setUserVisibleHint
//                    makeFragmentName(container.getId(), itemId)); 
            mCurTransaction.add(container.getId(), fragment,
                    getTag(position));
        } 
        if (fragment != mCurrentPrimaryItem) {
            fragment.setMenuVisibility(false);
            fragment.setUserVisibleHint(false);
        } 
 
        return fragment;
    } 
 
    @Override 
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (mCurTransaction == null) {
            mCurTransaction = mFragmentManager.beginTransaction();
        } 
        if (DEBUG) Log.v(TAG, "Detaching item #" + getItemId(position) + ": f=" + object
                + " v=" + ((Fragment) object).getView());
        mCurTransaction.detach((Fragment) object);
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getActivity
     * Used by an {@link Fragment} to install itself to the host activity. 
     * 
     * @see FragmentInstallable 
     */ 
    public static void installFragment(Fragment fragment) {
        final Activity a = fragment.getActivity();
        if (a instanceof FragmentInstallable) {
            ((FragmentInstallable) a).onInstallFragment(fragment);
        } 
    } 
 
    /** 
     * Used by an {@link Fragment} to uninstall itself from the host activity. 
     * 
     * @see FragmentInstallable 
     */ 
    public static void uninstallFragment(Fragment fragment) {
        final Activity a = fragment.getActivity();
        if (a instanceof FragmentInstallable) {
            ((FragmentInstallable) a).onUninstallFragment(fragment);
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: startActivityForResult
        } 
 
        if (resultTo == null) {
            startActivity(intent);
        } else { 
            resultTo.startActivityForResult(intent, resultRequestCode);
        } 
    } 
 
    @Override 
    public boolean hasNextButton() { 
        // PreferenceActivity#hasNextButton() is protected, so we need to expose it here. 
        return super.hasNextButton(); 
    } 
 
    @Override 
    public Button getNextButton() {
        // PreferenceActivity#getNextButton() is protected, so we need to expose it here. 
        return super.getNextButton(); 
    } 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: dismiss, isVisible
 
	@Override 
	protected void onCancelled() { 
		final FragmentManager fm = activity.getFragmentManager();
		final DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
		if (fragment != null && fragment.isVisible()) {
			fragment.dismiss();
		} 
		super.onCancelled(); 
	} 
 
	@Override 
	protected void onPostExecute(final File result) {
		final FragmentManager fm = activity.getFragmentManager();
		final DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
		if (fragment != null) {
			fragment.dismiss();
		} 
		super.onPostExecute(result);
		if (result != null && result.exists()) {
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: isDetached
 
            // Check to see if we already have a fragment for this tab, probably 
            // from a previously saved state.  If so, deactivate it, because our 
            // initial state is that a tab isn't shown. 
            mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
            if (mFragment != null && !mFragment.isDetached()) {
                FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction();
                ft.detach(mFragment);
                ft.commit();
            } 
        } 
 
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            if (mFragment == null) {
                mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
                ft.add(android.R.id.content, mFragment, mTag);
            } else { 
                ft.attach(mFragment);
            } 
        } 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setMenuVisibility, setUserVisibleHint
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getId
        @Override 
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            if (mParentFragment != null) {
                outState.putInt(KEY_DIALOG_ID, mDialogId);
                outState.putInt(KEY_PARENT_FRAGMENT_ID, mParentFragment.getId());
            } 
        } 
 
        @Override 
        public void onStart() { 
            super.onStart(); 
 
            if (mParentFragment != null && mParentFragment instanceof SettingsPreferenceFragment) {
                ((SettingsPreferenceFragment) mParentFragment).onDialogShowing();
            } 
        } 
 
        @Override 
        public Dialog onCreateDialog(Bundle savedInstanceState) {
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setUserVisibleHint
package com.teamboid.twitter.compat; 
 
import android.annotation.TargetApi; 
import android.app.Fragment; 
import android.os.Build; 
 
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
public class Api15 { 
 
	public static void setUserVisibleHint(Fragment fragment, boolean b) {
		fragment.setUserVisibleHint(b);
	} 
 
} 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: isHidden
        } 
        return result;
    } 
 
    protected static void showFragment(FragmentTransaction ft, Fragment f) {
        if ((f != null) && f.isHidden()) ft.show(f);
    } 
 
    protected static void hideFragment(FragmentTransaction ft, Fragment f) {
        if ((f != null) && !f.isHidden()) ft.hide(f);
    } 
} 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setMenuVisibility, setUserVisibleHint
	@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;
		} 
	} 
 
	@Override 
	public void finishUpdate(ViewGroup container) {
		if (mCurTransaction != null) {
			try { 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Fragment Questions & Answers:

Other Android Fragment Examples

7:	import android.view.ViewGroup;
8:	
9:	public class MoviesFragment extends Fragment {
10:	
11:		@Override

Read More

7:	import android.view.ViewGroup;
8:	
9:	public class GamesFragment extends Fragment {
10:	
11:		@Override

Read More

7:	import android.view.ViewGroup;
8:	
9:	public class TopRatedFragment extends Fragment {
10:	
11:		@Override

Read More

See Code Examples for Android Fragment Methods: