android图表库--androidplot onclick问题

标签 android androidplot

我正在尝试使用库“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();
        }
    });

非常感谢!!!

最佳答案

尝试使用“mySimpleXYPlot.redraw();”在“mySimpleXYPlot.disableAllMarkup();”之后

我很确定图表是在创建 View 时绘制的,因此当您在第一次绘制后设置它时,您将不得不重新绘制它。我认为,如果您在运行时更改图形上的某些内容,情况也是如此。

关于android图表库--androidplot onclick问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6522048/

相关文章:

android - 设置刷新 Activity 图

java - TabLayout 中的选项卡没有填满整个 ActionBar

android - 在 Kotlin 上将 JSON 字符串解析为 JsonObject/Map/MutableMap

android - 使用 androidx DialogFragment 创建 AlertDialog 时按钮样式错误

android - 尽管有 AsyncTask,但不确定的 ProgressBar 卡住了(不旋转)

android - 如何在 Androidplot 中设置 X 范围?

java - 从自定义 ListView 元素中的 Spinner getSelectedItem

android - 多次运行 Espresso 测试

android - 销售包括 AndroidPlot 在内的应用程序