Breno Macena
Breno Macena

Reputation: 449

Android bar chart: undo selection

There's some way to undo a selection on Mikephil charting? I have an application which opens an activity when I selects one value in a bar chart. That works fine, however, when I returns to activity that contains the chart, the selection remains. So, when I selects again, the selection is cleared and the activity does not open. What I want is ever I select a value on bar chart the function "onValueSelected" be executed. How can I do that?

That is the code fragment which calls assyncronously an activity when a value is selected.

      mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
                if(e.getVal() == 0);
                else {
                    GetClientesCadastradosDiaAsync task = new GetClientesCadastradosDiaAsync();
                    task.execute();
                }
            }

            @Override
            public void onNothingSelected() {
                // do nothing
            }
        });

Upvotes: 2

Views: 463

Answers (1)

Harsh Pandey
Harsh Pandey

Reputation: 831

At the end of your onValueSelected() method, call:

chart.highlightValues(null);

Now, this will only remove the highlighting. If you select that same bar again, onNothingSelected() will be called.

Therefore, in onNothingSelected(), again call onValueSelected(). You will have to pass the parameters here, but looks like you will only need the Entry parameter, and for the other 2 you can pass null.

Upvotes: 2

Related Questions