Start an activity

To create an activity please follow the steps :


  1. Start the visual studio and create the new project.
  2. Choose the android blank application from the project templates.
  3. By default the Xamarin.Android application creates an Activity called MainActivity.cs file the application


The MainActivity.cs contains the following code structure :

 [Activity(Label = "MANDDO", MainLauncher = true)]
  public class MainActivity : Activity
    {
       
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
        }

    }


Start an activity on button click :

[Activity(Label = "MANDDO", MainLauncher = true)]
  public class MainActivity : Activity
    {
       Button btnclick;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
           
            btnclick=FindViewById<Button>(Resource.Id.mybutton);
            
btnclick.Click+=delegate{

            this.StartActivity(typeof(LoginSignUpActivity));

           };
        }


    }

Where "LoginSignUpActivity" is the second activity that you want to open on button click.

No comments:

Post a Comment