Exemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            // Get the TextSwitcher view from the layout
            mSwitcher = (Android.Widget.TextSwitcher)FindViewById(Resource.Id.switcher);

            // BEGIN_INCLUDE(setup)
            // Set the factory used to create TextViews to switch between.
            mSwitcher.SetFactory(this);

            /*
             * Set the in and out animations. Using the fade_in/out animations
             * provided by the framework.
             */
            var animIn  = AnimationUtils.LoadAnimation(this, Android.Resource.Animation.FadeIn);
            var animOut = AnimationUtils.LoadAnimation(this, Android.Resource.Animation.FadeOut);

            mSwitcher.InAnimation  = animIn;
            mSwitcher.OutAnimation = animOut;
            // END_INCLUDE(setup)

            /*
             * Setup the 'next' button. The counter is incremented when clicked and
             * the new value is displayed in the TextSwitcher. The change of text is
             * automatically animated using the in/out animations set above.
             */
            var nextButton = (Button)FindViewById(Resource.Id.button);

            nextButton.Click += (sender, e) =>
            {
                mCounter++;
                // BEGIN_INCLUDE(settext)
                mSwitcher.SetText(String.ValueOf(mCounter));
                // END_INCLUDE(settext)
            };

            // Set the initial text without an animation
            mSwitcher.SetCurrentText(String.ValueOf(mCounter));
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _switcher = FindViewById <Android.Widget.TextSwitcher>(Resource.Id.Switcher);

            // BEGIN_INCLUDE(setup)
            // Set the factory used to create TextViews to switch between.
            _switcher.SetFactory(this);

            /*
             * Set the in and out animations. Using the fade_in/out animations
             * provided by the framework.
             */
            _switcher.InAnimation  = AnimationUtils.LoadAnimation(this, Android.Resource.Animation.FadeIn);
            _switcher.OutAnimation = AnimationUtils.LoadAnimation(this, Android.Resource.Animation.FadeOut);
            // END_INCLUDE(setup)

            /*
             * Setup the 'next' button. The counter is incremented when clicked and
             * the new value is displayed in the TextSwitcher. The change of text is
             * automatically animated using the in/out animations set above.
             */
            Button nextButton = (Button)FindViewById <Button>(Resource.Id.Button);

            nextButton.Click += delegate
            {
                // BEGIN_INCLUDE(settext)
                _mCounter++;
                _switcher.SetText(String.ValueOf(_mCounter));
                // END_INCLUDE(settext)
            };

            // Set the initial text without an animation
            _switcher.SetCurrentText(String.ValueOf(_mCounter));
        }