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