2011-06-29 12 views
1

私はライブラリ "androidplot"を使用しようとしています。それはonclicklistenerを供給しますか?コードをoncreate()に入れると、それが動作します。しかし、私がonclik()に入れると、うまく動作しません。誰かが私に理由を教えてもらえますか? これはXMLファイルです:アンドロイドチャートライブラリ - androidplot onclickの問題

<com.androidplot.xy.XYPlot 
    android:id="@+id/mySimpleXYPlot" 
    android:layout_width="743px" 
    android:layout_height="473px" 
    android:layout_marginTop="5px" 
    android:layout_marginLeft="5px" 
    android:layout_marginRight="0px" 
    title="Line Chart testing" 
    /> 

これは、Javaコードです:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

// initialize our XYPlot reference: 
    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 

    // add a new series 
    mySimpleXYPlot.addSeries(new SimpleXYSeries(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0))); 

    // reduce the number of range labels 
    mySimpleXYPlot.getGraphWidget().setRangeTicksPerLabel(4); 

    // reposition the domain label to look a little cleaner: 
    Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget(); 

    mySimpleXYPlot.position(domainLabelWidget,      // the widget to position 
          45,         // x position value, in this case 45 pixels 
          XLayoutStyle.ABSOLUTE_FROM_LEFT,  // how the x position value is applied, in this case from the left 
          0,          // y position value 
          YLayoutStyle.ABSOLUTE_FROM_BOTTOM,  // how the y position is applied, in this case from the bottom 
          AnchorPosition.LEFT_BOTTOM);   // point to use as the origin of the widget being positioned 

    // get rid of the visual aids for positioning: 
    mySimpleXYPlot.disableAllMarkup();}} 

それは動作しますが、私はonclicklistenerでこれを置けば、それは動作しません。コードは次のとおりです。

Button oneday = (Button) findViewById(R.id.oneday); 
    oneday.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      // initialize our XYPlot reference: 
      mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); 

      // add a new series 
      mySimpleXYPlot.addSeries(new SimpleXYSeries2(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0))); 

      // reduce the number of range labels 
      mySimpleXYPlot.getGraphWidget().setRangeTicksPerLabel(4); 

      // reposition the domain label to look a little cleaner: 
      Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget(); 

      mySimpleXYPlot.position(domainLabelWidget,      // the widget to position 
            45,         // x position value, in this case 45 pixels 
            XLayoutStyle.ABSOLUTE_FROM_LEFT,  // how the x position value is applied, in this case from the left 
            0,          // y position value 
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM,  // how the y position is applied, in this case from the bottom 
            AnchorPosition.LEFT_BOTTOM);   // point to use as the origin of the widget being positioned 

      // get rid of the visual aids for positioning: 
      mySimpleXYPlot.disableAllMarkup(); 
     } 
    }); 

多くの感謝!!!

+0

"それはうまくいかない"とはどういう意味ですか?それは例外をスローしますか?何もしませんか?ボタンをクリックするとonclick()の –

+0

が表示されます。何もしない – nich

+0

あなたの2つの例の間には1つの違いがあります:最初に 'SimpleXYSeries'を使い、第2の例で' SimpleXYSeries2'を使います。問題を引き起こしていないことを確認するために 'SimpleXYSeries'に変更してみてください。 –

答えて

1

"mySimpleXYPlot.redraw();"後で "mySimpleXYPlot.disableAllMarkup();"

グラフが作成されたときに描画されていることは間違いないので、最初に描画した後にグラフを描画する必要があります。実行時にグラフ上の何かを変更すると同じことが起こります。

関連する問題