Visual Studio 2015-Xamarin-Android-获取"resource.id不包含xxx的定义"当我尝试在.cs文件中执行任何操作时 [英] Visual Studio 2015 - Xamarin - Android - Getting "resource.id does not contain a definition for xxx" when I try to do anything in the .cs file

查看:156
本文介绍了Visual Studio 2015-Xamarin-Android-获取"resource.id不包含xxx的定义"当我尝试在.cs文件中执行任何操作时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2015添加其他活动.cs和布局axml.

我对Xamarin和Android开发非常陌生,但是使用VB和C#已有几年的开发经验.我在Android 4.2上有一个简单的应用,随着我的前进,它变得越来越复杂.一件很简单的事情,我想向项目添加一个额外的GpsAction.cs和相应的Gps.axml布局.似乎不可能找到正确的组合语法来实现这一目标.我有一个mainActivity与main.axml.在VS 2015中,添加新的内容非常简单,但是我不断收到"resource.id不包含"的定义,我非常感谢您对此提供的帮助

namespace AddCam
{
[Activity(Label = "GpsActivity")]
public class GpsActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.GpsLayout);

        string c = FindViewById<TextView>(**Resource.Id.textView1**).Text;
        // Create your application here
    }
}

解决方案

(VS 2019)我没有执行以前的解决方案,什么也没做,我遇到了同样的问题,而我的解决方案是删除'&'从TextView的文本中,我试图将文本设置为"text& text",即使&&(尽管它像WindowsForms中的助记符一样)都无法正常工作,所以我必须将其删除并修复./p>

Adding Additional Activity .cs and Layout axml Using Visual Studio 2015.

I'm very new to Xamarin and Android development, but have been a developer for a few years using VB and now C#. I have a simple app on Android 4.2 that is getting more complicated as I go along. The simple matter us that I want to add an additional GpsAction.cs and corresponding Gps.axml layout to the project. It seems impossible to find the right combination syntax to achive this. I have a mainActivity with main.axml. In VS 2015 it's very simple to add new but I keep getting "resource.id does not contain a definition for" I would really appreciate your help with this

namespace AddCam
{
[Activity(Label = "GpsActivity")]
public class GpsActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.GpsLayout);

        string c = FindViewById<TextView>(**Resource.Id.textView1**).Text;
        // Create your application here
    }
}

解决方案

(VS 2019) I did the previous solutions and nothing, I had the same problem and the solution for me was to remove '&' from the text of TextView, I was trying to Set the text to "text&text" even &&(I though it was like mnemonics as in WindowsForms) didn't work so I had to remove it and it fixed.

这篇关于Visual Studio 2015-Xamarin-Android-获取"resource.id不包含xxx的定义"当我尝试在.cs文件中执行任何操作时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆