2016-11-04 38 views
0

我正在使用xamarin在visual studio 2015中使用android。我想添加一個圖表,因此對於基本瞭解,我跟進了oxyplot並下載了文檔(示例代碼)。現在我只是複製源代碼,但通過編寫代碼。當我到達FindViewById<PlotView>(Resource.Id)點時,我無法在其中找到Id字段。爲了更好的理解,請參閱波紋圖像和代碼Xamarin android無法找到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) 
    } 
}} 

我不知道我錯過了什麼。 任何幫助,將不勝感激

+1

你能提供您Main.axml佈局,使我們能夠確保你有視圖和id設置是否正確?你應該在你的視圖中有「android:id =」@ + id/plot_view「」。 –

回答

0

您試圖訪問該ID在XML文件中定義 像這樣

`機器人:ID = 「@ + ID /內容」

,這樣就可以指出到具有ID,或者它或者在另一個文件中像被細化的資源值 - > id.xml

+0

id應該在resources.cs中的ID類中創建,但它不存在 – faisal1208