Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #add(int,Fragment,String) with a null tag.

Usage

From source file:com.cloudbees.gasp.activity.TwitterStreamActivity.java

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

    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Use simple FrameLayout for ListFragment
    setContentView(R.layout.gasp_frame_layout);

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ListFragment list = new ListFragment();
    ft.add(R.id.fragment_content, list);

    // Use a simple TextView layout for ArrayAdapter constructor
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_generic_textview);

    // Map ArrayAdapter to ListFragment
    list.setListAdapter(mAdapter);//from www .j ava2  s  .  co  m

    // RESTResponderFragments call setRetainedInstance(true) in onCreate()
    TwitterResponderFragment responder = (TwitterResponderFragment) fm
            .findFragmentByTag(getString(R.string.twitter_responder));
    if (responder == null) {
        responder = new TwitterResponderFragment();

        ft.add(responder, getString(R.string.twitter_responder));
    }

    ft.commit();
}

From source file:com.songnick.blogdemo.NetEaseDemo_Activity.java

private void addContentLayout() {

    FragmentManager fm = getFragmentManager();

    FragmentTransaction ft = fm.beginTransaction();

    ft.add(R.id.content_frame, new NetEaseDemo_Fragment());
    ft.commitAllowingStateLoss();//from  w  ww . j av a  2  s.  c o  m
}

From source file:curiosamente.com.app.activities.main.MainActivity.java

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

    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    MainFragment mainFragment = new MainFragment();
    fragmentTransaction.add(R.id.main_layout, mainFragment);
    fragmentTransaction.commit();// w w  w  .  j a  v a  2 s.c o m

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            Bar[] bars = (Bar[]) intent.getExtras().get(HttpService.RETURNOBJECT_EXTRA_PROPERTY);
            //                FragmentManager fm = getFragmentManager();
            //                FragmentTransaction fragmentTransaction = fm.beginTransaction();
        }
    };

    mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main);
    mDrawerTextView = (TextView) findViewById(R.id.facebook_name_text);
    mDrawerLogoutButton = (Button) mDrawerLayout.findViewById(R.id.facebook_logout_button);
    mDrawerImage = (ImageView) findViewById(R.id.profileImage);

    Intent intent = new Intent(this, HttpService.class);
    intent.putExtra(HttpService.URL_EXTRA_PROPERTY, "http://192.168.0.13:8080/bar");
    intent.putExtra(HttpService.CLASS_EXTRA_PROPERTY, Bar[].class);
    startService(intent);

    initDrawer();
}

From source file:com.hero.fm.FileExplorerTabActivity.java

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

    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    if (USE_HTCSTYLE) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        SetupActionBar();/*from  w  ww  .  j  av a  2  s. c o  m*/
    }
    if (!USE_ACTIONBAR)
        getActionBar().hide();

    super.onCreate(savedInstanceState);

    final int rootId = 1;
    FrameLayout viewRoot = new FrameLayout(this);
    viewRoot.setId(rootId);
    setContentView(viewRoot);
    mCarousel = new Carousel();
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(rootId, mCarousel);
    ft.commit();
    registerForContextMenu(viewRoot);
}

From source file:com.ariesmcrae.eskwela.celebtweet.MainActivity.java

/** Add Friends Fragment to Activity */
private void addFriendsFragment() {
    mFriendsFragment = new FriendsFragment();
    mFriendsFragment.setArguments(getIntent().getExtras());

    FragmentTransaction transaction = mFragmentManager.beginTransaction();
    transaction.add(R.id.fragment_container, mFriendsFragment);

    transaction.commit();/* www  . ja  va2  s  .c om*/
}

From source file:com.example.android.reward.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new EndTripFragment();
    Bundle args = new Bundle();
    args.putInt(EndTripFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);/* www  .j a v a2 s.  c  om*/

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    //ft.replace(R.id.content_frame, fragment);
    ft.add(R.id.content_frame, fragment);

    ft.addToBackStack("null");
    ft.commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mMainTopicsFragment = new MainTopicsFragment();

    android.app.FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.fragment_container, mMainTopicsFragment);
    fragmentTransaction.commit();/*from   ww  w  .  java  2 s. com*/

    mToolbar = (Toolbar) findViewById(R.id.mainToolbar);
    mToolbar.setTitle("");
    mToolbar.setTitleMargin(140, 0, 0, 0);
    setSupportActionBar(mToolbar);

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, mToolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            SharedPreferences data = getSharedPreferences("DataSave", Context.MODE_PRIVATE);
            String username = data.getString("USERNAME", "User Name");

            if (drawerFlag) {
                mUserNameTextView = (TextView) drawerView.findViewById(R.id.userName);
                mUserNameTextView.setText(username);
                drawerFlag = false;
            }
        }
    };
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

}

From source file:com.cloudbees.gasp.activity.PlacesActivity.java

private void addPlacesFragments() {
    mSearchFragment = new NearbySearchFragment() {
        public void onSuccess(Places places) {
            showLocations(places);/* w  ww  . j av a 2  s  . c  o  m*/
            checkToken(places);
        }

        public void onFailure(String status) {
            Log.e(TAG, "Google Places API search failed: status = " + status);
        }
    };

    mDetailsFragment = new PlaceDetailsFragment() {
        @Override
        public void onSuccess(PlaceDetails placeDetails) {
            showDetails(placeDetails);
        }

        @Override
        public void onFailure(String status) {
            Log.e(TAG, "Google Places API search failed: status = " + status);
        }
    };

    mAddEventFragment = new AddEventFragment() {
        @Override
        public void onSuccess(EventResponse eventResponse) {
            Log.d(TAG, "Event Added: " + eventResponse.getEvent_id());
        }

        @Override
        public void onFailure(String status) {
            Log.e(TAG, "Google Places API search failed: status = " + status);
        }
    };

    mDeleteEventFragment = new DeleteEventFragment() {
        @Override
        public void onSuccess(EventResponse eventResponse) {
            Log.d(TAG, "Event Deleted");
        }

        @Override
        public void onFailure(String status) {
            Log.e(TAG, "Google Places API search failed: status = " + status);
        }
    };

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(mSearchFragment, getString(R.string.fragment_location_search));
    ft.add(mDetailsFragment, getString(R.string.fragment_place_details));
    ft.add(mAddEventFragment, getString(R.string.fragment_add_event));
    ft.add(mDeleteEventFragment, getString(R.string.fragment_delete_event));
    ft.commit();
}

From source file:tv.piratemedia.lightcontroler.controlPreferences.java

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

    setContentView(R.layout.control_prefs);

    // Display the fragment as the main content.
    FragmentManager mFragmentManager = getFragmentManager();
    FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
    PrefsFragment mPrefsFragment = new PrefsFragment();
    mFragmentTransaction.add(R.id.prefs_layout, mPrefsFragment);
    mFragmentTransaction.commit();//  w  w w.j av a  2 s .c  om

    if (Build.VERSION.SDK_INT == 21) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    }

    mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(mActionBarToolbar);
    mActionBarToolbar.setNavigationIcon(R.drawable.ic_ab_back_material);
    mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            controlPreferences.this.finish();
        }
    });
}

From source file:com.cloudbees.gasp.activity.GaspRESTLoaderActivity.java

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

    // Set main content view for Gasp! Reviews
    setContentView(R.layout.gasp_review_activity);

    // Use the Fragments API to display review data
    FragmentManager fm = getFragmentManager();
    ListFragment list = (ListFragment) fm.findFragmentById(R.id.gasp_review_content);
    if (list == null) {
        list = new ListFragment();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.gasp_review_content, list);
        ft.commit();/*w  w  w .  jav a2  s. c  om*/
    }

    // Array adapter provides access to the review list data
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_review_list);
    list.setListAdapter(mAdapter);

    // Load shared preferences from res/xml/preferences.xml (first time only)
    // Subsequent activations will use the saved shared preferences from the device
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences gaspSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    Log.i(TAG, "Using Gasp Server URI: " + gaspSharedPreferences.getString("gasp_endpoint_uri", ""));
    Uri gaspReviewsUri = Uri.parse(gaspSharedPreferences.getString("gasp_endpoint_uri", ""));

    // Loader arguments: LoaderManager will maintain the state of our Loaders
    // and reload if necessary. 
    Bundle args = new Bundle();
    Bundle params = new Bundle();
    args.putParcelable(ARGS_URI, gaspReviewsUri);
    args.putParcelable(ARGS_PARAMS, params);

    // Initialize the Loader.
    getLoaderManager().initLoader(LOADER_GASP_REVIEWS, args, this);

    // Use gasp-mongo REST service
    new ReviewsRequest().execute();

    try {
        LocationsRequest locations = new LocationsRequest(
                new SpatialQuery(new Location(-122.1139858, 37.3774655), 0.005));

        List<GeoLocation> locationList = locations.execute().get();
        for (GeoLocation geoLocation : locationList) {
            Log.i(TAG, geoLocation.getName());
            Log.i(TAG, " " + geoLocation.getFormattedAddress());
            Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLng()));
            Log.i(TAG, " " + String.valueOf(geoLocation.getLocation().getLat()));
        }
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
}