Android 在“创建”上设置按钮文本,而不是将文本设置为“定义”

Android 在“创建”上设置按钮文本,而不是将文本设置为“定义”,android,xamarin,xamarin.android,Android,Xamarin,Xamarin.android,我有一个在创建时更改文本的代码 public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(

我有一个在创建时更改文本的代码

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

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Button btnbut = FindViewById<Button>(Resource.Id.btnbut);
            TextView txtvw = FindViewById<TextView>(Resource.Id.txtView);
            txtvw.Text = "Hello World";
            btnbut.Text = "Hello WOrld";
        }
    }
公共类main活动:活动
{
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
按钮btnbut=findviewbyd(Resource.Id.btnbut);
TextView txtvw=findviewbyd(Resource.Id.txtView);
Text=“你好,世界”;
btnbut.Text=“你好,世界”;
}
}
My main.axml:


当我使用emulator运行并打开应用程序时,文本与main.axml上的define保持相同,而不是define
OnCreate

您的代码是正确的,应该会导致:

尝试在解决方案上执行“全部清除/全部构建”,然后在模拟器上重试应用程序

注意:如果仍然没有在模拟器上正确更新应用程序:

在模拟器中:

Setting / Apps / Select your app / *Uninstall*

我想我得到了你的建议,我不使用xamrain,但我想这是错误,请尝试更改

SetContentView(Resource.Layout.Main);


因为您的版面名称是“我的主要”而不是“主要”

谢谢@SushiHangover@TouchyVivace没问题,快乐编码:)是的,你是绝对正确的,见Raj brother,但正如我说的,我不使用xamrain,所以我不知道它们在xamrain中是否可以接受。如果是native,那么您甚至无法使用这种命名约定构建项目
SetContentView(Resource.Layout.Main);
SetContentView(Resource.Layout.My main);