Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.SendDataToFragment);

            var sendDataToFragment = FindViewById <Button>(Resource.Id.sendDataToFragment);

            sendDataToFragment.Click += (sender, args) =>
            {
                //TODO: Start a new transaction
                using (var transaction = FragmentManager.BeginTransaction())
                {
                    //TODO: use animations to transition between fragments
                    transaction.SetCustomAnimations(
                        Android.Resource.Animator.FadeIn,
                        Android.Resource.Animator.FadeOut);

                    var randomColorValue = new Random();
                    var randomColor      = new Color(
                        randomColorValue.Next(0, 255),
                        randomColorValue.Next(0, 255),
                        randomColorValue.Next(0, 255));

                    var fragmentToAdd = FragmentToAdd.CreateFragmentToAdd(randomColor);


                    //TODO: replace the fragment on click
                    transaction.Replace(Resource.Id.container, fragmentToAdd);

                    //Commit your changes
                    transaction.Commit();
                }
            };
        }
Example #2
0
        private void SendDataToFragmentOnClick(object sender, EventArgs eventArgs)
        {
            var displayDetailActivity = Activity as IDisplayDetail;

            if (displayDetailActivity != null && displayDetailActivity.CanDisplayDetail)
            {
                var randomColorValue = new Random();
                var randomColor      = new Color(
                    randomColorValue.Next(0, 255),
                    randomColorValue.Next(0, 255),
                    randomColorValue.Next(0, 255));

                displayDetailActivity.DisplayDetail(FragmentToAdd.CreateFragmentToAdd(randomColor));
            }
            else
            {
                StartActivity(new Intent(this.Activity, typeof(SendDataToFragmentActivity)));
            }
        }