Example usage for android.support.v4.app FragmentManager findFragmentById

List of usage examples for android.support.v4.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.support.v4.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:com.nijie.samples.facebookfoo.FacebookFooMainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    Log.d("facebookfoo ###############", "FacebookFooMainActivity create!");
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }/*w w  w  .  java2s.c  o  m*/

    setContentView(R.layout.main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setPublishPermissions(PAGE_PERMISSION);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            FacebookFooMainActivity.this.user = user;
            Log.d("facebookfoo ###############", "onUserInfoFetched!");
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postRegularPostButton = (Button) findViewById(R.id.regularPostUpdateButton);
    postRegularPostButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostRegularPost();
        }
    });

    postUnpublishedPostButton = (Button) findViewById(R.id.postUnpublishedPostButton);
    postUnpublishedPostButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostUnpublishedPost();
        }
    });

    listAllPostsButton = (Button) findViewById(R.id.listAllPostsButton);
    listAllPostsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickListAllPosts();
        }
    });

    showStatisticsButton = (Button) findViewById(R.id.showStatisticsButton);
    showStatisticsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickShowStatistics();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);

    Log.d("facebookfoo ###############", "OnCreate Exit!");
}

From source file:com.example.scrumptious.PickerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickers);/*w  ww .  j a  v  a2s .c  o m*/

    Bundle args = getIntent().getExtras();
    FragmentManager manager = getSupportFragmentManager();
    Fragment fragmentToShow = null;
    Uri intentUri = getIntent().getData();

    if (FRIEND_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            friendPickerFragment = new FriendPickerFragment();
            friendPickerFragment.setSettingsFromBundle(args);
            friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS);
        } else {
            friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
            ;
        }

        friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                PickerActivity.this.onError(error);
            }
        });
        friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = friendPickerFragment;

    } else if (PLACE_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            placePickerFragment = new PlacePickerFragment();
            placePickerFragment.setSettingsFromBundle(args);
        } else {
            placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
        }
        placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged(PickerFragment fragment) {
                finishActivity(); // call finish since you can only pick one place
            }
        });
        placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                PickerActivity.this.onError(error);
            }
        });
        placePickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = placePickerFragment;
    } else {
        // Nothing to do, finish
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
}

From source file:org.bwgz.quotation.activity.QuotationActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    Log.d(TAG, String.format("onLoadFinished - loader: %s  cursor: %s (count: %d)", loader, cursor,
            cursor != null ? cursor.getCount() : 0));

    FragmentManager fragmentManager = getSupportFragmentManager();

    switch (loader.getId()) {
    case LOADER_ID_QUTOATION:
        if (fragmentManager != null) {
            QuotationFragment fragment = (QuotationFragment) fragmentManager
                    .findFragmentById(R.id.quotationFragment);

            if (fragment != null) {
                fragment.setQuotation(cursor);
            }//from   w w w.  j  a v  a2 s .c  om
        }
        if (cursor.getCount() != 0) {
            setLoadState(LoadState.LOADED);
        }
        break;
    case LOADER_ID_AUTHOR:
        if (fragmentManager != null) {
            AuthorFragment fragment = (AuthorFragment) fragmentManager.findFragmentById(R.id.authorFragment);
            if (fragment != null) {
                fragment.setAuthors(cursor);
            }
        }
        break;
    }
}

From source file:com.jtechme.apphub.views.ManageReposActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    ((FDroidApp) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);

    FragmentManager fm = getSupportFragmentManager();
    if (fm.findFragmentById(android.R.id.content) == null) {
        /*// ww  w .j ava 2s .c  o m
         * Need to set a dummy view (which will get overridden by the
         * fragment manager below) so that we can call setContentView().
         * This is a work around for a (bug?) thing in 3.0, 3.1 which
         * requires setContentView to be invoked before the actionbar is
         * played with:
         * http://blog.perpetumdesign.com/2011/08/strange-case-of
         * -dr-action-and-mr-bar.html
         */
        if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT <= 13) {
            setContentView(new LinearLayout(this));
        }

        listFragment = new RepoListFragment();

        fm.beginTransaction().add(android.R.id.content, listFragment).commit();
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // title is "Repositories" here, but "F-Droid" in VIEW Intent chooser
    getSupportActionBar().setTitle(R.string.menu_manage);
}

From source file:edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity.java

/**
 * Display the UI defined in activity_photographs.xml upon activity start.
 *///from   w w w  . j  a  va2s .c  om
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_photographs);

    /*
     * Add "up" button functionality in the left of application icon in
     * top-left corner, allowing user to return to "welcome" screen
     */
    final ActionBar ab = this.getSupportActionBar();
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    /*
     * Create "navigation spinner" in activity action bar that allows user to
     * view a different content screen
     */
    final ArrayAdapter<CharSequence> navDropDownAdapter = ArrayAdapter.createFromResource(this,
            R.array.ab_content_activities_names, R.layout.ab_navigation_dropdown_item);
    ab.setListNavigationCallbacks(navDropDownAdapter, this);
    ab.setSelectedNavigationItem(ContentActivity.PHOTOGRAPHS.getABDropDownListIndex());

    // Retrieve name of lighthouse that user is viewing
    final Bundle extras = this.getIntent().getExtras();
    final String lighthouseNameSelected = extras.getString("lighthousename");

    // Lighthouse data guaranteed to exist ("Welcome" activity performs data
    // existence validation)
    final LighthouseDataParser lighthouseInformationParser = new LighthouseDataParser(
            this.getApplicationContext(), lighthouseNameSelected);
    lighthouseInformationParser.parseLighthouseData();
    this.currentLighthouse = lighthouseInformationParser.getLighthouse();

    /*
     * Complete Flickr downloading task only if a network connection exists
     * _and_ the cache is empty or contains information about a lighthouse
     * other than the "desired" one
     */
    this.userConnectedToInternet = this.networkConnectionExists();
    FlickrDownloadHandler downloadHandler = null;

    if (this.userConnectedToInternet) {
        if (!this.photoCacheExists()) {
            if (!PhotographsActivity.downloadingThreadStarted) {
                Log.d("LIGHTNAVDEBUG", "Creating dialog...");

                // Display dialog informing user about download progress
                final ProgressDialog flickrPhotoDownloadDialog = new ProgressDialog(this,
                        ProgressDialog.STYLE_SPINNER);
                flickrPhotoDownloadDialog.setTitle("Downloading Flickr photos");
                flickrPhotoDownloadDialog.setMessage("Downloading photographs from Flickr...");
                flickrPhotoDownloadDialog.setCancelable(true);

                flickrPhotoDownloadDialog.show();

                final HashSet<Photograph> flickrPhotos = new HashSet<Photograph>();

                /*
                 * Start background thread that will complete actual downloading
                 * process
                 */
                PhotographsActivity.downloadingThreadStarted = true;
                downloadHandler = new FlickrDownloadHandler(this, this.currentLighthouse, flickrPhotos,
                        flickrPhotoDownloadDialog);

                final FlickrPhotoDownloadThread downloadThread = new FlickrPhotoDownloadThread(
                        this.getApplicationContext(), this.currentLighthouse, downloadHandler,
                        PhotographsActivity.XML_DOWNLOAD_COMPLETE, PhotographsActivity.INTERRUPT);
                Log.d("LIGHTNAVDEBUG", "Flickr download XML thread started");
                downloadThread.start();

                /*
                 * Interrupt (stop) currently-running thread if user cancels
                 * downloading operation explicitly
                 */
                flickrPhotoDownloadDialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface di) {
                        if (downloadThread.isAlive()) {
                            downloadThread.interrupt();
                        } else if (PhotographsActivity.this.parseOutputThread != null
                                && PhotographsActivity.this.parseOutputThread.isAlive()) {
                            PhotographsActivity.this.parseOutputThread.interrupt();
                        } else {
                            // Do nothing
                        }
                    }
                });
            }
        } else {

            final ArrayList<Photograph> lighthousePhotos = this.currentLighthouse.getAlbum()
                    .get(ActivityVisible.PHOTOGRAPHS);
            lighthousePhotos.clear();
            final File downloadCacheDir = new File(this.getFilesDir() + "/download-cache/");
            final File[] downloadCacheDirContents = downloadCacheDir.listFiles();
            for (int i = 0; i < downloadCacheDirContents.length; i++) {
                final String downloadCacheDirContentName = downloadCacheDirContents[i].getName();
                final String[] downloadCacheDirContentPieces = downloadCacheDirContentName.split("_");
                final Long photoID = Long.parseLong(downloadCacheDirContentPieces[2]);
                final String ownerName = downloadCacheDirContentPieces[3].replace("~", " ");
                final String creativeCommonsLicenseIDString = downloadCacheDirContentPieces[4].substring(0, 1);
                final int creativeCommonsLicenseID = Integer.parseInt(creativeCommonsLicenseIDString);
                final CreativeCommonsLicenseType licenseType = CreativeCommonsLicenseType
                        .convertToLicenseEnum(creativeCommonsLicenseID);
                lighthousePhotos.add(new Photograph(photoID, ownerName, licenseType,
                        "/download-cache/" + downloadCacheDirContentName));
            }
            this.currentLighthouse.getAlbum().put(ActivityVisible.PHOTOGRAPHS, lighthousePhotos);
        }
    }

    if (!this.userConnectedToInternet || this.userConnectedToInternet && this.photoCacheExists()
            || downloadHandler != null && downloadHandler.getFlickrOperationsComplete()) {
        // Display first photograph as "selected" photograph in top-left corner
        // by default
        final ArrayList<Photograph> photoSet = this.currentLighthouse.getAlbum()
                .get(ActivityVisible.PHOTOGRAPHS);
        final Photograph currentPhotoOnLeftSide = photoSet.get(0);

        final ImageView currentPhotoView = (ImageView) this.findViewById(R.id.iv_photographs_current_image);
        if (this.userConnectedToInternet) {
            currentPhotoView.setImageDrawable(Drawable.createFromPath(
                    PhotographsActivity.this.getFilesDir() + currentPhotoOnLeftSide.getInternalStorageLoc()));
        } else {
            currentPhotoView.setImageResource(currentPhotoOnLeftSide.getResID());
        }

        // Add credits for "default" main photograph
        final TextView owner = (TextView) this.findViewById(R.id.tv_photographs_photographer);
        final TextView licenseType = (TextView) this.findViewById(R.id.tv_photographs_license);
        owner.setText("Uploaded by: " + currentPhotoOnLeftSide.getOwner());
        licenseType.setText("License: " + currentPhotoOnLeftSide.getLicenseTypeAbbreviation());

        /*
         * Display Google Map as a SupportMapFragment (instead of MapFragment
         * for compatibility with Android 2.x)
         */
        /*
         * BIG thanks to http://www.truiton.com/2013/05/
         * android-supportmapfragment-example/ for getting this part of the app
         * working
         */
        final FragmentManager fm = this.getSupportFragmentManager();
        final Fragment mapFragment = fm.findFragmentById(R.id.frag_photographs_map);
        final SupportMapFragment smf = (SupportMapFragment) mapFragment;
        smf.getMap();
        final GoogleMap supportMap = smf.getMap();

        /*
         * Center map at lighthouse location, at a zoom level of 12 with no
         * tilt, facing due north
         */
        final LatLng lighthouseLocation = new LatLng(this.currentLighthouse.getCoordinates().getLatitude(),
                this.currentLighthouse.getCoordinates().getLongitude());
        final float zoomLevel = 12.0f;
        final float tiltAngle = 0.0f;
        final float bearing = 0.0f;
        final CameraPosition cameraPos = new CameraPosition(lighthouseLocation, zoomLevel, tiltAngle, bearing);
        supportMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos));

        /*
         * Allows user to open a maps application (such as Google Maps) upon
         * selecting the map fragment
         */
        /*
         * Courtesy of:
         * http://stackoverflow.com/questions/6205827/how-to-open-standard
         * -google-map-application-from-my-application
         */
        supportMap.setOnMapClickListener(new OnMapClickListener() {

            @Override
            public void onMapClick(LatLng lighthouseCoordinates) {
                final String uri = String.format(Locale.US, "geo:%f,%f", lighthouseCoordinates.latitude,
                        lighthouseCoordinates.longitude);
                final Intent googleMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                PhotographsActivity.this.startActivity(googleMapsIntent);
            }
        });

        this.gv = (GridView) this.findViewById(R.id.gv_photographs_thumbnails);

        /*
         * Photographs in the "current lighthouse album" are from Flickr if the
         * album is empty or if the first (or _any_) of the elements in the
         * album do not have a "proper" static resource ID
         */
        this.photosFromFlickr = this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).isEmpty()
                || this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).iterator().next()
                        .getResID() == 0;

        final LighthouseImageAdapter thumbnailAdapter = new LighthouseImageAdapter(this,
                this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS), this.photosFromFlickr);

        this.gv.setAdapter(thumbnailAdapter);

        this.gv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                // Determine which photograph from the list was selected...
                final Photograph photoClicked = (Photograph) thumbnailAdapter.getItem(position);
                final int photoClickedResID = photoClicked.getResID();

                // ...and change the information in the top-left corner
                // accordingly
                if (PhotographsActivity.this.userConnectedToInternet) {
                    currentPhotoView.setImageDrawable(Drawable.createFromPath(
                            PhotographsActivity.this.getFilesDir() + photoClicked.getInternalStorageLoc()));
                } else {
                    currentPhotoView.setImageResource(photoClickedResID);
                }
                owner.setText("Uploaded by: " + photoClicked.getOwner());
                licenseType.setText("License: " + photoClicked.getLicenseTypeAbbreviation());
            }
        });
    }
}

From source file:de.schildbach.wallet.ui.monitor.NetworkMonitorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.network_monitor_content);

    final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager);

    final FragmentManager fm = getSupportFragmentManager();

    if (pager != null) {
        final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs);
        pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title,
                R.string.network_monitor_block_list_title);

        final PagerAdapter pagerAdapter = new PagerAdapter(fm);

        pager.setAdapter(pagerAdapter);/*from ww w. j a  v  a  2 s  .  c  om*/
        pager.setOnPageChangeListener(pagerTabs);
        pager.setPageMargin(2);
        pager.setPageMarginDrawable(R.color.bg_less_bright);

        peerListFragment = new PeerListFragment();
        blockListFragment = new BlockListFragment();
    } else {
        peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment);
        blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment);
    }
}

From source file:com.example.gps_project.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {/*from   w w w .  j  a  v  a2s  .c  o m*/
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            // We just store our selection in the Application for other activities to look at.
            FriendPickerApplication application = (FriendPickerApplication) getApplication();
            application.setSelectedUsers(friendPickerFragment.getSelection());
            setResult(RESULT_OK, null);
            finish();
        }
    });
}

From source file:com.facebook.samples.hellofacebook.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {/*w ww. ja v a  2  s  .com*/
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked() {
            // We just store our selection in the Application for other activities to look at.
            HelloFacebookApplication application = (HelloFacebookApplication) getApplication();
            application.setSelectedUsers(friendPickerFragment.getSelection());

            setResult(RESULT_OK, null);
            finish();
        }
    });
}

From source file:com.beacon.afterui.views.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {//from w  w w. ja  v  a  2 s .  c o  m
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            // We just store our selection in the Application for other activities to look at.
            AfterYouApplication application = (AfterYouApplication) getApplication();
            application.setSelectedUsers(friendPickerFragment.getSelection());

            setResult(RESULT_OK, null);
            finish();
        }
    });
}

From source file:heartware.com.heartware_master.FB_PickerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fb_pickers);

    Bundle args = getIntent().getExtras();
    FragmentManager manager = getSupportFragmentManager();
    Fragment fragmentToShow = null;// ww w .j a  v  a 2s  .  c o m
    Uri intentUri = getIntent().getData();

    if (FRIEND_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            friendPickerFragment = new FriendPickerFragment();
            friendPickerFragment.setSettingsFromBundle(args);
            friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS);
        } else {
            friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
            ;
        }

        friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                FB_PickerActivity.this.onError(error);
            }
        });
        friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = friendPickerFragment;

    } else if (PLACE_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            placePickerFragment = new PlacePickerFragment();
            placePickerFragment.setSettingsFromBundle(args);
        } else {
            placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
        }
        placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged(PickerFragment fragment) {
                finishActivity(); // call finish since you can only pick one place
            }
        });
        placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                FB_PickerActivity.this.onError(error);
            }
        });
        placePickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = placePickerFragment;
    } else {
        // Nothing to do, finish
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
}