Библиотека диаграмм Android Проблема с androidplot onclick

Я пытаюсь использовать библиотеку "androidplot". Он поставляет onclicklistener? Если я помещу код в oncreate(), он будет работать. но если я введу onclick(), это не сработает. Может ли кто-нибудь сказать мне, почему? Это 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();
        }
    });

Большое спасибо!!!


person SPG    schedule 29.06.2011    source источник
comment
Что значит не получится? Выдает ли это исключение? Это ничего не делает?   -  person Mark Allison    schedule 29.06.2011
comment
для onclick(), когда я нажимаю кнопку. ничего не делать   -  person SPG    schedule 29.06.2011
comment
Между двумя вашими примерами есть одно различие: в первом вы используете SimpleXYSeries, а во втором - SimpleXYSeries2. Попробуйте изменить второе значение на SimpleXYSeries, чтобы убедиться, что проблема не в этом.   -  person Mark Allison    schedule 29.06.2011


Ответы (1)


Попробуйте с "mySimpleXYPlot.redraw();" после "mySimpleXYPlot.disableAllMarkup(); "

Я совершенно уверен, что график рисуется при создании представлений, поэтому, когда вы настраиваете его после того, как он был нарисован в первый раз, вам придется его перерисовывать. То же самое произойдет, если вы измените что-то на графике во время выполнения, я думаю.

person Rasmus Øvlesen    schedule 07.05.2012