protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_item_detail); // Show the Up button in the action bar. SupportActionBar.SetDisplayHomeAsUpEnabled(true); // savedInstanceState is non-null when there is fragment state // saved from previous configurations of this activity // (e.g. when rotating the screen from portrait to landscape). // In this case, the fragment will automatically be re-added // to its container so we don't need to manually add it. // For more information, see the Fragments API guide at: // // http://developer.android.com/guide/components/fragments.html // if (savedInstanceState == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. Bundle arguments = new Bundle(); arguments.PutInt(ItemDetailFragment.ARG_ITEM_ID, Intent.GetIntExtra(ItemDetailFragment.ARG_ITEM_ID, 0)); ItemDetailFragment fragment = new ItemDetailFragment(); fragment.Arguments = arguments; SupportFragmentManager.BeginTransaction().Add(Resource.Id.item_detail_container, fragment).Commit(); } }
/// <summary> /// Callback method from <seealso cref="ItemListFragment.Callbacks"/> indicating that /// the item with the given ID was selected. /// </summary> public void OnItemSelected(int id) { if (mTwoPane) { // In two-pane mode, show the detail view in this activity by // adding or replacing the detail fragment using a // fragment transaction. Bundle arguments = new Bundle(); arguments.PutInt(ItemDetailFragment.ARG_ITEM_ID, id); ItemDetailFragment fragment = new ItemDetailFragment(); fragment.Arguments = arguments; SupportFragmentManager.BeginTransaction().Replace(Resource.Id.item_detail_container, fragment).Commit(); } else { // In single-pane mode, simply start the detail activity // for the selected item ID. Intent detailIntent = new Intent(this, typeof(ItemDetailActivity)); detailIntent.PutExtra(ItemDetailFragment.ARG_ITEM_ID, id); StartActivity(detailIntent); } }