I would like to be able to move in Xamarin through different Activities, from the MainActivity from a button I can go to the following activity (MenuNumbers):
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't get it to work for me, 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);
};
What am I doing wrong?
Thank you very much
Instead of changing the content of the view using
SetContentView
, you can start new activities usingStartActivity
.So instead of
You would do the following:
Where
MenuNumeros
is the name of the class that inherits from activitySimilarly, in the
Click
button event in the activityMenuNumeros
, instead of putting aSetContentView
you could useStartActivity(typeof(Secuencial))
.You can refer to the official Xamarin documentation for more details:
https://developer.xamarin.com/recipes/android/fundamentals/activity/start_an_activity/
Of course, always to start another activity it must be called with:
The part
“actividadAiniciar”
is the name of your new activity to execute. This means that you must create a different activity for each window to display.And to return to the previous activity again you can do it with the button
“Back”
or by putting in the control that will execute the action. Usually located at the top 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 fill up with instances of the same activity.