android - Xamarin android 找不到 id 字段

标签 android visual-studio-2015 xamarin.android oxyplot

我正在使用 visual studio 2015 中的 xamarin 在 android 上工作。我想添加一个图表,所以为了基本理解,我跟进了 oxyplot并下载了文档(示例代码)。现在我只是复制源代码,而是通过编写代码。当我到达点FindViewById<PlotView>(Resource.Id)我找不到 Id其中的字段。为了更好的理解,请看下面的图片和代码

enter image description here

下面是我复制的代码

using Android.App;
using Android.OS;

using OxyPlot.Xamarin.Android;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

namespace AndroidApp1
{
  [Activity(Label = "AndroidApp1", MainLauncher = true, Icon = "@drawable/icon")]

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);

        PlotView view = FindViewById<PlotView>(Resource.Id.plot_view);
        view.Model = CreatePlotModel();
    }

    private PlotModel CreatePlotModel()
    {
        var plotModel = new PlotModel { Title = "OxyPlot Demo" };

        plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
        plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Maximum = 10, Minimum = 0 });

        var series1 = new LineSeries
        {
            MarkerType = MarkerType.Circle,
            MarkerSize = 4,
            MarkerStroke = OxyColors.White
        };

        series1.Points.Add(new DataPoint(0.0, 6.0));
        series1.Points.Add(new DataPoint(1.4, 2.1));
        series1.Points.Add(new DataPoint(2.0, 4.2));
        series1.Points.Add(new DataPoint(3.3, 2.3));
        series1.Points.Add(new DataPoint(4.7, 7.4));
        series1.Points.Add(new DataPoint(6.0, 6.2));
        series1.Points.Add(new DataPoint(8.9, 8.9));

        plotModel.Series.Add(series1);

        return plotModel;
    }
}}

波纹管是我正在写的

using Android.App;
using Android.OS;

using OxyPlot.Xamarin.Android;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;


namespace SampleChart
{
[Activity(Label = "SampleChart", MainLauncher = true, Icon = "@drawable/icon")]
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);
        PlotView view = FindViewById<PlotView>(Resource.Id)
    }
}}

我不知道我错过了什么。 任何帮助将不胜感激

最佳答案

您尝试访问的 ID 必须在 Xml 文件中定义 像这样的东西

`android:id="@+id/Content"

这样您就可以指出具有 ID 的资源,或者它必须在另一个文件中进行优化,例如 values->id.xml

关于android - Xamarin android 找不到 id 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40420747/

相关文章:

安卓 : can i attach picture when i tweet via native Twitter app

Android - 翻译 View 后仍保留空白

c++ - 将适用于 Visual Studio 2015 的 Visual C++ Redistributable 添加到 InstallShield

c# - Refit库如何设置超时

php - 我们可以让 Flex-LAMP 应用程序在 Android 上运行吗

android - 构建 android 镜像时出错,jack 服务器失败

c# - Showing MDI Child - 一个只在屏幕上出现一毫秒可见的随机形式

c# - (ILC0005错误)我无法编译UWP x64/x86发布项目

c# - 如何在 xamarin 的 ListView 中使用 OnItemLongClick

c# - 如果没有发送任何内容,Stream.Read 不会返回任何内容