You're mixing different ways to hookup buttons and methods.
Option 1 - Programmatically
MainActivity.cs
using System;
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
namespace Example
{
[Activity(Label = "Example", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.SetContentView(Resource.Layout.Main);
this.FindViewById<Button>(Resource.Id.ForwardButton).Click += this.Forward;
}
public void Forward(object sender, EventArgs e)
{
this.SetContentView(Resource.Layout.Main2);
this.FindViewById<Button>(Resource.Id.BackButton).Click += this.Back;
}
public void Back(object sender, EventArgs e)
{
this.SetContentView(Resource.Layout.Main);
this.FindViewById<Button>(Resource.Id.ForwardButton).Click += this.Forward;
}
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/ForwardButton"
android:text="Forward"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Main2.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/CheckedTextView"
android:layout_width="match_parent"
android:layout_height="326dp"
android:enabled="false" />
<Button
android:id="@+id/BackButton"
android:text="Back"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
In XML
MainActivity.cs
using System;
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
namespace Example
{
[Activity(Label = "Example", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.SetContentView(Resource.Layout.Main);
}
[Java.Interop.Export("OnClick")]
public void OnClick (View view)
{
var button = (Button)view;
if (button.Id == Resource.Id.ForwardButton) {
this.SetContentView(Resource.Layout.Main2);
} else if (button.Id == Resource.Id.BackButton) {
this.SetContentView(Resource.Layout.Main);
}
}
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/ForwardButton"
android:text="Forward"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="OnClick" />
</LinearLayout>
Main2.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/CheckedTextView"
android:layout_width="match_parent"
android:layout_height="326dp"
android:enabled="false" />
<Button
android:id="@+id/BackButton"
android:text="Back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="OnClick" />
</LinearLayout>