Button click event on different layout not working help

siufungleungsiufungleung GBMember
edited December 2015 in Xamarin.Android

Hi i have problem on actual run time error in my application.
I have 2 layout and the main activity.cs wanted to use the button click event to move between layout 1 and 2 but getting error on returning to layout 1
The error occurs on btnlogout.click saying "object reference not set to an instance of an object"

Part of my MainActivity.cs

        // Load resource Main.axml
        var btnGuest = FindViewById<Button>(Resource.Id.btnGuest); //Button Guest
        var btnfb = FindViewById<Button>(Resource.Id.btnfb); //Button Facebook
        var btngplus = FindViewById<Button>(Resource.Id.btngplus); //Button Google+

        //Load resource ProductHome.axml
        var btnmenu = FindViewById<Button>(Resource.Id.btnmenu); // button menu
        var btnlogout = FindViewById<Button> (Resource.Id.btnlogout); // button logout

        // Event
        // button Guest Main.axml
        btnGuest.Click += (object sender, EventArgs e) =>
        {
            SetContentView(Resource.Layout.ProductHome); //Opens ProductHome.axml
        };
        // button logout ProductHome.axml
        btnlogout.Click += (object sender, EventArgs e) =>
        {
            SetContentView (Resource.Layout.Main); //Returns to Main.axml
        };

Main.axml (layout 1)

ProductHome.axml (layout 2)

Tagged:

Answers

Sign In or Register to comment.