Example usage for android.app FragmentManager findFragmentById

List of usage examples for android.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.app FragmentManager findFragmentById.

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction.

Usage

From source file:Main.java

public static Fragment getFragmentInLayout(FragmentManager fragmentManager, int fragmentId) {
    return fragmentManager.findFragmentById(fragmentId);
}

From source file:com.richtodd.android.quiltdesign.app.BrowserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browser);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    m_urlArgument = getIntent().getStringExtra(ARG_URL);

    FragmentManager fm = getFragmentManager();

    // Create color settings fragment.
    {/*from w w w  . j  a  va2  s. c o  m*/
        Fragment f = fm.findFragmentById(R.id.layout_container);
        if (f == null) {
            f = BrowserFragment.create(m_urlArgument);
            fm.beginTransaction().add(R.id.layout_container, f).commit();
        }
    }
}

From source file:com.bulletingroupblast.bulletingroupblast.GroupOverviewFragment.java

/** The click event for the ListView lstGroups, opens a specific group activity
 *
 * @param adView/*w  ww.j a v a 2 s.co  m*/
 * @param v
 * @param position
 * @param id
 */
private void onOrgItemClick(AdapterView<?> adView, View v, int position, long id) {
    // Move to another activity
    try {
        // Open the group activity that was selected

        // Intent is for switching to a different activity
        /*Intent intent = new Intent(this,
        com.bulletingroupblast.bulletingroupblast.OrganizationActivity.class);
                
        String message = adView.getItemAtPosition(position).toString();
        intent.putExtra(EXTRA_MESSAGE, message);        // Adds the text value to the intent
        startActivity(intent);*/
        Activity myActivity = getActivity();
        FragmentManager myFragMan = myActivity.getFragmentManager();
        Fragment navFrag = myFragMan.findFragmentById(R.id.lstGroupMenu);

        //            myActivity.onNa

    } catch (Exception e) {
        //            Toast.makeText(v.g(), e.getMessage().toString(), Toast.LENGTH_LONG).show(); // Show a message in toast
    }
}

From source file:com.samebits.beacon.locator.ui.activity.BaseActivity.java

protected Fragment getFragmentInstance(int id) {
    android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager != null) {
        Fragment fragment = fragmentManager.findFragmentById(id);
        if (fragment != null) {
            return fragment;
        }/*from w  w  w .  j  a  va 2s  .c  o  m*/
    }
    return null;
}

From source file:koma.movieapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    Toolbar toolbar = getActionBarToolbar();
    toolbar.setTitle(R.string.title_search);
    toolbar.setNavigationIcon(R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//from w  w  w . ja v  a 2  s. co m
        public void onClick(View view) {
            navigateUpToFromChild(SearchActivity.this, IntentCompat
                    .makeMainActivity(new ComponentName(SearchActivity.this, PopularMoviesActivity.class)));
        }
    });

    FragmentManager fm = getFragmentManager();
    mMoviesFragment = (MoviesFragment) fm.findFragmentById(R.id.fragment_container);

    String query = getIntent().getStringExtra(SearchManager.QUERY);
    query = query == null ? "" : query;
    mQuery = query;

    if (mMoviesFragment == null) {
        mMoviesFragment = new MoviesFragment();
        //Bundle args = intentToFragmentArguments(getIntent());
        Bundle args = new Bundle();
        args.putString("title", "Search");
        args.putString("searchString", query);
        mMoviesFragment.setArguments(args);
        fm.beginTransaction().add(R.id.fragment_container, mMoviesFragment).commit();
    }

    if (mSearchView != null) {
        mSearchView.setQuery(query, false);
    }

    overridePendingTransition(0, 0);
}

From source file:com.microsoft.office365.starter.FilesFolders.FileDetailActivity.java

@Override
public void onOperationComplete(final OperationResult opResult) {
    this.runOnUiThread(new Runnable() {

        @Override// w  w  w . ja  v  a  2 s .  com
        public void run() {
            if (mDialog.isShowing())
                mDialog.dismiss();

            Toast.makeText(FileDetailActivity.this, opResult.getOperationResult(), Toast.LENGTH_LONG).show();
            if (opResult.getId().equals("FileDeleted")) {
                // The file displayed may be the one just deleted
                // so clear the display to be safe.
                O365APIsStart_Application application = (O365APIsStart_Application) getApplication();
                application.setDisplayedFile(null);
                FragmentManager fm = getFragmentManager();
                FileDetailFragment fragment = (FileDetailFragment) fm
                        .findFragmentById(R.id.file_detail_container);
                if (fragment != null)
                    fragment.refresh(null);
            }
            if (opResult.getId().equals("FileContentsUpdate")) {
                // refresh the display to reflect new file contents
                FragmentManager fm = getFragmentManager();
                FileDetailFragment fragment = (FileDetailFragment) fm
                        .findFragmentById(R.id.file_detail_container);
                if (fragment != null)
                    fragment.refresh(((O365APIsStart_Application) getApplication()).getDisplayedFile());
            }
        }
    });

}

From source file:com.google.samples.apps.sergio.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    Toolbar toolbar = getActionBarToolbar();
    toolbar.setTitle(R.string.title_search);
    toolbar.setNavigationIcon(R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/* w ww .  j av  a  2  s  . c om*/
        public void onClick(View view) {
            navigateUpToFromChild(SearchActivity.this, IntentCompat
                    .makeMainActivity(new ComponentName(SearchActivity.this, BrowseSessionsActivity.class)));
        }
    });

    FragmentManager fm = getFragmentManager();
    mSessionsFragment = (SessionsFragment) fm.findFragmentById(R.id.fragment_container);

    String query = getIntent().getStringExtra(SearchManager.QUERY);
    query = query == null ? "" : query;
    mQuery = query;

    if (mSessionsFragment == null) {
        mSessionsFragment = new SessionsFragment();
        Bundle args = intentToFragmentArguments(
                new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSearchUri(query)));
        mSessionsFragment.setArguments(args);
        fm.beginTransaction().add(R.id.fragment_container, mSessionsFragment).commit();
    }

    if (mSearchView != null) {
        mSearchView.setQuery(query, false);
    }

    overridePendingTransition(0, 0);
}

From source file:com.saarang.samples.apps.iosched.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.saarang.samples.apps.iosched.R.layout.activity_search);

    Toolbar toolbar = getActionBarToolbar();
    toolbar.setTitle(com.saarang.samples.apps.iosched.R.string.title_search);
    toolbar.setNavigationIcon(com.saarang.samples.apps.iosched.R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//from  w  w  w .  ja  va2 s  .c  o m
        public void onClick(View view) {
            navigateUpToFromChild(SearchActivity.this, IntentCompat
                    .makeMainActivity(new ComponentName(SearchActivity.this, BrowseSessionsActivity.class)));
        }
    });

    FragmentManager fm = getFragmentManager();
    mSessionsFragment = (SessionsFragment) fm
            .findFragmentById(com.saarang.samples.apps.iosched.R.id.fragment_container);

    String query = getIntent().getStringExtra(SearchManager.QUERY);
    query = query == null ? "" : query;
    mQuery = query;

    if (mSessionsFragment == null) {
        mSessionsFragment = new SessionsFragment();
        Bundle args = intentToFragmentArguments(new Intent("com.saarang.samples.apps.iosched.SESSION_VIEW",
                ScheduleContract.Sessions.buildSearchUri(query)));
        mSessionsFragment.setArguments(args);
        fm.beginTransaction().add(com.saarang.samples.apps.iosched.R.id.fragment_container, mSessionsFragment)
                .commit();
    }

    if (mSearchView != null) {
        mSearchView.setQuery(query, false);
    }

    overridePendingTransition(0, 0);
}

From source file:com.microsoft.office365.starter.views.FileDetailActivity.java

@Override
public void onOperationComplete(final OperationResult opResult) {
    this.runOnUiThread(new Runnable() {

        @Override/*w ww .jav a 2 s . c o m*/
        public void run() {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }

            Toast.makeText(FileDetailActivity.this, opResult.getOperationResult(), Toast.LENGTH_LONG).show();
            if (opResult.getId().equals("FileDeleted")) {
                // The file displayed may be the one just deleted
                // so clear the display to be safe.
                O365APIsStart_Application application = (O365APIsStart_Application) getApplication();
                application.setDisplayedFile(null);
                FragmentManager fm = getFragmentManager();
                FileDetailFragment fragment = (FileDetailFragment) fm
                        .findFragmentById(R.id.file_detail_container);
                if (fragment != null)
                    fragment.refresh(null);
            }
            if (opResult.getId().equals("FileContentsUpdate")) {
                // refresh the display to reflect new file contents
                FragmentManager fm = getFragmentManager();
                FileDetailFragment fragment = (FileDetailFragment) fm
                        .findFragmentById(R.id.file_detail_container);
                if (fragment != null) {
                    O365APIsStart_Application application = (O365APIsStart_Application) getApplication();
                    fragment.refresh(application.getDisplayedFile());
                }
            }

        }
    });

}

From source file:com.richtodd.android.quiltdesign.app.ThemeEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_theme_edit);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    m_themeNameArgument = getIntent().getStringExtra(ARG_THEME_NAME);

    if (savedInstanceState != null) {
        m_saveAsThemeName = savedInstanceState.getString("saveAsThemeName");
    }//  w  w w  .jav  a2 s.c  o  m

    ActionBar ab = getActionBar();
    ab.setTitle("Edit Theme");
    ab.setSubtitle(getCurrentThemeName());

    FragmentManager fm = getFragmentManager();

    // Create color settings fragment.
    {
        Fragment f = fm.findFragmentById(R.id.layout_themeEditFragment);
        if (f == null) {
            f = ThemeEditFragment.create(m_themeNameArgument);
            fm.beginTransaction().add(R.id.layout_themeEditFragment, f).commit();
        }
    }
}