【问题标题】:SetContentView(Resource.Layout.V2T) CS0117 Error 'Resource.Layout' does not contain a definition for 'V2T'SetContentView(Resource.Layout.V2T) CS0117 错误“Resource.Layout”不包含“V2T”的定义
【发布时间】:2018-09-29 10:44:32
【问题描述】:

使用 Visual Studio 开发 Xamarin 跨平台 APP。我已将特定的 Android 代码添加到 Android 特定版本中。尝试编译时出现 CS0117 错误。我在 Resources/layout 文件夹中有一个“V2T.axml”文件。 CS代码中出现错误的行是:

SetContentView(Resource.Layout.V2T);

知道有什么问题吗?

另外还有 2 个 CS0117 错误,原因是“Resource.Id”不包含定义错误 - 但我已经定义了这两个资源。

有什么想法吗?

CS:

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // set the isRecording flag to false (not recording)
        isRecording = false;

        // Set our view to: V2T.axml
        SetContentView(Resource.Layout.V2T);

        // get the resources from the layout
        recButton = FindViewById<Button>(Resource.Id.btnRecord);
        textBox = FindViewById<TextView>(Resource.Id.textYourText);

V2T.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"
android:weightSum="3">
<LinearLayout
    android:orientation="horizontal"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout1"
    android:layout_weight="1"
    android:gravity="center">
    <Button
        android:text="Start Recording"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnRecord" />
</LinearLayout>
<LinearLayout
    android:orientation="vertical"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout2"
    android:layout_weight="1">
    <TextView
        android:text="Your text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"
        android:layout_marginLeft="5dp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/textYourText"
        android:textColor="#ffedf01d"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp" />
</LinearLayout>
<LinearLayout
    android:orientation="horizontal"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayout3"
    android:layout_weight="1" />
 </LinearLayout>

【问题讨论】:

  • 考虑发布更多代码
  • 这里是代码 sn-p: CS: protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // 将 isRecording 标志设置为 false(不录制) isRecording = false; // 将我们的视图设置为:V2T.axml SetContentView(Resource.Layout.V2T); // 从布局中获取资源 recButton = FindViewById
  • SetContentView(Resource.Layout.V2T); 这一行有什么问题?
  • 不确定 - 我在一个独立的应用程序中使用了这个确切的代码并且它有效。我错过了什么?
  • 请发布错误

标签: c# setcontentview


【解决方案1】:

清理解决方案并重建,布局xml没有成功构建应该可以解决它

【讨论】:

  • 编辑 CS 代码时,IntelliSense 编辑器不知道“V2T.axml”资源。如上所述,我从一个独立的 CS 项目中复制了文件,并将它们放入带有 Android、iOS 和 Windows 项目的更大的 Xamarin Forms 项目中。我将所有内容都放入了 Android 项目文件中。使用“Resource.Layout.V2T”语句时是否需要指定名称空间或项目文件?该语句如何知道要查看我的“EnSpect.Android”/Resources/layout 文件夹以找到 V2T.axml?
  • IntelliSense 在“资源/布局”中看不到任何文件。我错过了什么?我在该文件夹中也有“Tabbar.axml”和“Toolbar.axml” - 但 IntelliSense 看不到它们。
  • 已修复!我将 CS 文件中的命名空间从“EnSpect”更正为“EnSpect.Droid”。感谢所有帮助过的人!
猜你喜欢
  • 2019-08-18
  • 2018-01-05
  • 2019-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-17
  • 2011-02-18
  • 1970-01-01
相关资源
最近更新 更多