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

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

问题描述

使用 Visual Studio 2015 添加额外的 Activity .cs 和布局 axml.

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

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) 我做了之前的解决方案,什么也没做,我遇到了同样的问题,我的解决方案是删除 '&'从 TextView 的文本中,我试图将文本设置为text&text",即使 &&(虽然它就像 WindowsForms 中的助记符)也不起作用,所以我不得不删除它并修复它.

(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天全站免登陆