我正在使用xamarin在visual studio 2015中使用android。我想添加一个图表,所以为了基本的理解,我跟着struct
并下载了文档(示例代码)。现在我只是通过编写代码来复制源代码。当我到达oxyplot
点时,我无法在其中找到FindViewById<PlotView>(Resource.Id)
字段。为了更好地理解,请参阅下面的图像和代码
Bellow是我正在复制的代码
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;
}
}}
我不知道我错过了什么。 任何帮助将不胜感激
答案 0 :(得分:1)
您尝试访问的ID必须在Xml文件中定义 像这样的东西
`机器人:ID =&#34; @ + ID /内容和#34;
这样你就可以指出具有ID的资源,或者它必须在另一个文件中进行细化,例如values-&gt; id.xml