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:it.sasabz.android.sasabus.classes.dialogs.ConnectionDialog.java

private void fillData() {
    MyXMLConnectionAdapter adapter = new MyXMLConnectionAdapter(list);
    ListView listv = (ListView) findViewById(android.R.id.list);
    listv.setAdapter(adapter);/* w ww  .jav  a 2  s  .  c om*/
    listv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> l, View v, int position, long id) {
            XMLConnection conn = (XMLConnection) list.get(position);
            if (conn instanceof XMLJourney) {
                SimpleDateFormat simple = new SimpleDateFormat("HH:mm");
                String fromtext = "(" + conn.getDeparture().getStation().getHaltestelle().replace(" -", ")");
                String totext = "(" + conn.getArrival().getStation().getHaltestelle().replace(" -", ")");
                FragmentManager fragmentManager = fragment.getFragmentManager();
                FragmentTransaction ft = fragmentManager.beginTransaction();

                Fragment old = fragmentManager.findFragmentById(R.id.onlinefragment);
                if (old != null) {
                    ft.remove(old);
                }
                Fragment fragment = null;
                try {
                    fragment = new WayFragment(((XMLJourney) conn).getAttribut("NUMBER"), fromtext, totext,
                            simple.format(conn.getDeparture().getArrtime()),
                            simple.format(conn.getArrival().getArrtime()));
                } catch (Exception e) {
                    fragment = old;
                    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                    builder.setCancelable(false);
                    builder.setMessage(R.string.error_connection);
                    builder.setTitle(R.string.error);
                    builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            dialog.dismiss();
                        }
                    });
                    builder.create();
                    builder.show();
                    fragmentManager.popBackStack();
                }
                ft.add(R.id.onlinefragment, fragment);
                ft.addToBackStack(null);
                ft.commit();
                fragmentManager.executePendingTransactions();
                dismiss();
            }
        }
    });
}

From source file:com.mrpoid.mrplist.ui.MrplistActivity.java

@Override
protected void onCreate(Bundle arg0) {
    setTheme(PreferencesProvider.Interface.General.getThemeImage(0) == 1
            ? R.style.Theme_Sherlock_Light_DarkActionBar
            : R.style.Theme_Sherlock);//from  w w  w  .ja  va  2s . com

    super.onCreate(arg0);
    Log.i(TAG, "onCreate");

    setContentView(R.layout.activity_main);

    getSupportActionBar().setDisplayUseLogoEnabled(true);

    FragmentManager fm = getSupportFragmentManager();
    if ((listFmg = (MrpListFragment) fm.findFragmentById(android.R.id.content)) == null) {
        listFmg = new MrpListFragment();
        fm.beginTransaction().add(android.R.id.content, listFmg).commit();
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    initSkin();

    addScreenSizeNavigation();
}

From source file:it.smartcampuslab.riciclo.MapFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    abActivity = (ActionBarActivity) getActivity();
    abActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    abActivity.getSupportActionBar().setHomeButtonEnabled(true);

    FragmentManager fm = getChildFragmentManager();
    mMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container);
    if (mMapFragment == null) {
        mMapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.map_container, mMapFragment).commit();
    }/*from www .  ja  v a2s. c  om*/
}

From source file:eu.masconsult.bgbanking.activity.HomeActivity.java

@Override
protected void onStart() {
    super.onStart();

    EasyTracker.getInstance().activityStart(this);

    FragmentManager fm = getSupportFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        AccountsListFragment list = new AccountsListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }/*from   w  w  w  .  ja  v a  2  s. c om*/
}

From source file:edu.mit.mobile.android.livingpostcards.MainActivity.java

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    final FragmentManager fm = getSupportFragmentManager();

    Fragment f = fm.findFragmentById(android.R.id.content);

    final String tag = (String) tab.getTag();

    // first remove anything that's not what we want
    if (f != null && !tag.equals(f.getTag())) {
        ft.detach(f);//from   w  w w .j a v a 2 s.c  o m
        f = null;
    }

    // search to see if there's one stashed away
    if (f == null) {
        f = fm.findFragmentByTag(tag);
    }

    // and reattach / create anything
    if (f != null) {
        ft.attach(f);
    } else {
        ft.add(android.R.id.content, instantiateFragment(tag), tag);
    }
}

From source file:it.sasabz.android.sasabus.fragments.OrarioFragment.java

@Override
public void onItemClick(AdapterView<?> av, View v, int position, long id) {
    // TODO Auto-generated method stub
    Passaggio orario = list.get(position);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();

    Fragment fragment = fragmentManager.findFragmentById(R.id.onlinefragment);
    if (fragment != null) {
        ft.remove(fragment);/*from w  w w  .  j av  a2  s. com*/
    }
    fragment = new WayFragment(bacino, linea, arrival, orario);
    ft.add(R.id.onlinefragment, fragment);
    ft.addToBackStack(null);
    ft.commit();
    fragmentManager.executePendingTransactions();
    /*
    Intent showWay = new Intent(this, ShowWayActivity.class);
    showWay.putExtra("orario", orario);
    showWay.putExtra("destinazione", destinazione);
    showWay.putExtra("linea", linea);
    showWay.putExtra("bacino", bacino.getId());
    startActivity(showWay);
    */
}

From source file:mobisocial.bento.anyshare.ui.FeedItemListActivity.java

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

    mMusubi = mManager.getMusubi();//from  w  w  w.  ja  v  a2s . c om
    setContentView(R.layout.activity_feeditemlist);

    FragmentManager fm = getSupportFragmentManager();
    mFeedItemListFragment = (FeedItemListFragment) fm.findFragmentById(R.id.fragment_itemlist);

    mMusubi.getFeed().registerStateObserver(mStateObserver);
}

From source file:com.vinidsl.googleioextended.ui.fragment.MapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_map, container, false);

    piso1 = (TextView) rootView.findViewById(R.id.textViewFloorOne);
    piso2 = (TextView) rootView.findViewById(R.id.textViewFloorTwo);

    MapsInitializer.initialize(getActivity());

    switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity())) {
    case ConnectionResult.SUCCESS:

        android.support.v4.app.FragmentManager myFM = getChildFragmentManager();
        final SupportMapFragment myMAPF = (SupportMapFragment) myFM.findFragmentById(R.id.map);
        googlemap = myMAPF.getMap();/*from w  w w .j a va  2  s. co m*/
        googlemap.setMyLocationEnabled(true);
        final View mapView = myFM.findFragmentById(R.id.map).getView();
        if (mapView.getViewTreeObserver().isAlive()) {
            mapView.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                        @Override
                        public void onGlobalLayout() {
                            // TODO now can work with the map
                            mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                            googlemap.moveCamera(
                                    CameraUpdateFactory.newLatLngZoom(new LatLng(-16.500484, -68.134246), 25));
                            piso1.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    piso1.setBackgroundColor(getResources().getColor(R.color.accent));
                                    piso2.setBackgroundColor(getResources().getColor(R.color.white));
                                    showFloorOne();
                                }
                            });

                            piso2.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    piso2.setBackgroundColor(getResources().getColor(R.color.accent));
                                    piso1.setBackgroundColor(getResources().getColor(R.color.white));
                                    showFloorTwo();
                                }
                            });
                            type = PreferencesHelper.getInt(PreferencesHelper.MAP, getActivity());
                            PreferencesHelper.putInt(PreferencesHelper.MAP, 0, getActivity());
                            switch (type) {
                            case 1:
                                piso1.setBackgroundColor(getResources().getColor(R.color.accent));
                                piso2.setBackgroundColor(getResources().getColor(R.color.white));
                                showFloorOne();
                                break;
                            case 2:
                                piso2.setBackgroundColor(getResources().getColor(R.color.accent));
                                piso1.setBackgroundColor(getResources().getColor(R.color.white));
                                showFloorTwo();
                                break;
                            case 3:
                                piso2.setBackgroundColor(getResources().getColor(R.color.accent));
                                piso1.setBackgroundColor(getResources().getColor(R.color.white));
                                showFloorTwo();
                                break;
                            }
                        }
                    });
        }
        break;
    case ConnectionResult.SERVICE_MISSING:
        // Todo install google play services
        break;
    case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
        // Todo go to playstore to upload google play services
        break;
    default:
        // Todo some error happends try again later
    }

    return rootView;
}

From source file:io.amira.zen.core.ZenFragment.java

public void setMapFrag() {
    getActivity().runOnUiThread(new Runnable() {
        @Override//w  w w .java2  s  .  c  om
        public void run() {
            FragmentManager fm = getChildFragmentManager();
            mapFrag = (ZenMap) fm.findFragmentById(mapContainerId);
            if (mapFrag == null) {
                //ZenLog.l("MAP FRAGMENT NULL: CREATING IT");
                mapFrag = ZenMap.create();
                fm.beginTransaction().add(mapContainerId, mapFrag).commit();
                // fix
                map = null;
            }
        }
    });
}

From source file:de.aw.monma.reports.ActivityReports.java

/**
 * Erstezt ein Fragment im container und entfernt dabei den Header und Footer
 *
 * @param f//from   w w w. j a v  a2  s.  c o m
 *         MonMaFragment fuer Container
 */
private void replaceFragment(AWFragment f) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(container, f, f.getTAG());
    Fragment footer = fm.findFragmentById(reportSummenFooter);
    if (footer != null) {
        ft.remove(footer);
    }
    Fragment header = fm.findFragmentById(reportZeitraumHeader);
    if (header != null) {
        ft.remove(header);
    }
    ft.addToBackStack(null).commit();
}