1

ライブラリ「androidplot」を使おうとしています。onclicklistenerを提供していますか?コードをoncreate()に入れると、機能します。しかし、onclik()に入れると、機能しません。誰かが理由を教えてもらえますか?これはXMLファイルです:

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

どうもありがとう!!!

4

1 に答える 1

1

「mySimpleXYPlot.redraw();」で試してください 「mySimpleXYPlot.disableAllMarkup();」の後

ビューの作成時にグラフが描画されることは間違いないので、最初に描画した後でグラフを設定するときは、再描画する必要があります。実行時にグラフ上の何かを変更した場合も同じだと思います。

于 2012-05-07T14:30:29.193 に答える