OnClick事件在android中的achartengine Donut图表中无效?

时间:2017-03-20 11:19:05

标签: android achartengine

我想点击图表中的每个切片,然后我必须根据点击每个切片显示一个弹出窗口。我已经实施了onclicklistener,但它无效。

代码:

点击部分:

gv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SeriesSelection seriesSelection = gv.getCurrentSeriesAndPoint();
                    if (seriesSelection != null) {
                        int seriesIndex = seriesSelection.getSeriesIndex();
                        String selectedSeries = "Income";
                        if (seriesIndex == 0)
                            selectedSeries = "Income";
                        else
                            selectedSeries = "Expense";

                        int amount = (int) seriesSelection.getValue();
                        Toast.makeText(
                                getActivity(),
                                selectedSeries + " in " + "" + " : " + amount,
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });

渲染部分:

public GraphicalView createIntent(List<double[]> values1, int[] colors, List<String[]> titles) {

        DefaultRenderer renderer = buildCategoryRenderer(colors);
        renderer.setApplyBackgroundColor(false);
        renderer.setShowLegend(false);
        renderer.setShowLabels(false);
        renderer.setStartAngle(chartStartAngle); // 0 is 90 degree
        renderer.setLabelsColor(Color.BLACK);
        //renderer.setBackgroundColor(ContextCompat.getColor(get));
        renderer.setScale((float) 1.40);
        renderer.setPanEnabled(false);
        renderer.setZoomEnabled(false);
        renderer.setClickEnabled(true);//
        renderer.setSelectableBuffer(100);

        return ChartFactory.getDoughnutChartView(getActivity().getApplicationContext(),
                buildMultipleCategoryDataset("Project", titles, values1),
                renderer);
    }

0 个答案:

没有答案