XAMARIN, call another activity

0

I would like to be able to move in Xamarin for different Activity, from the MainActivity from a button I can go to the next activity (MenuNumeros):

 base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);

        Button button = FindViewById<Button>(Resource.Id.btnNumeros);
        button.Click += delegate
        {
            SetContentView(Resource.Layout.MenuNum);

        };            

But from this activity I need to go back to a third activity that I can not make it work, I do it from the btnSequential button and the new activity is called Sequential:

 base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.MenuNum);

        Button button = FindViewById<Button>(Resource.Id.btnSecuencial);
        button.Click += delegate
        {
            SetContentView(Resource.Layout.Secuencial);

        };

Where am I failing?

Thank you very much

    
asked by Fran Pino 05.04.2017 в 17:42
source

2 answers

2

Instead of changing the content of the view using SetContentView , you can start new activities through StartActivity .

So, instead of

button.Click += (sender, args) =>
{
    SetContentView(Resource.Layout.MenuNum);
};

You would do the following:

button.Click += (sender, args) =>
{
    StartActivity(typeof(MenuNumeros));
};

Where MenuNumeros is the name of the class that inherits from activity

public class MenuNumeros : Activity
{
  protected override void OnCreate(Bundle bundle)
  {
    base.OnCreate(bundle);
    ...
  }
}

Similarly, in the event Click of the button in the activity MenuNumeros , instead of putting a SetContentView you could use StartActivity(typeof(Secuencial)) .

You can refer to the official Xamarin documentation for more details:

link

    
answered by 06.04.2017 / 20:22
source
1

Of course, always to start another activity you should call:

StartActivity(typeof(actividadAiniciar));

The “actividadAiniciar” part is the name of your new activity to be executed. This means that you must create a different activity for each window to be displayed.

And to return again to the previous activity you can do it with the “Back” button or by putting in the control that will execute the action. Usually located in the upper left: Finish();

With this I want to tell you that you are not going to put the StartActivity instruction again to return since you would be filled with instances of the same activity.

    
answered by 01.12.2018 в 17:54