我用MPAndroidChart做了一个条形图。我做了一个自定义标记视图类来查看条的值。
我会在几秒钟后移除或隐藏视图。它应该起到敬酒的作用。但我做不到。
这首先是一个问题,因为当我第一次触摸图表时,它变得可见,只有当我找到正确的点击条件时它才会消失。
有人知道怎么解决这个问题吗?
我的代码中有:

mChart.invalidate();
mv = new CustomMarkerView(getContext(), R.layout.alert_chart, position, jsonResponse);
mChart.setMarker(mv);

我的客户视图是
public class CustomMarkerViewextends MarkerView {

public TextView correct;
public TextView wrong ;
public int position;
public JSONArray jsonArray;

public CustomMarkerView(Context context, int layoutResource, int pos, JSONArray json) {
    super(context, layoutResource);

    correct = (TextView) findViewById(R.id.correct);
    wrong = (TextView) findViewById(R.id.wrong);

    position = pos;
    jsonArray = json;

}

@Override
public void refreshContent(Entry e, Highlight highlight) {
    switch (position){
        case 1:
            try {
                correct.setText(getContext().getString(R.string.correct_alert) + "   " + jsonArray.getJSONObject((int)(e.getX())).getString("TP"));
                wrong.setText(getContext().getString(R.string.wrong_alert) + "   " + jsonArray.getJSONObject((int)(e.getX())).getString("FP"));
            } catch (JSONException e1) {
                e1.printStackTrace();
            } catch (ParseException e1) {
                e1.printStackTrace();
            }

            break;
        case 2:
            try {
                correct.setText(getContext().getString(R.string.tpr_alert) + "   " + Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("TPR"))*100.0)/100.0);
                wrong.setText(getContext().getString(R.string.msr_alert) + "   " + Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("MSR"))*100.0)/100.0);
            } catch (JSONException e1) {
                e1.printStackTrace();
            } catch (ParseException e1) {
                e1.printStackTrace();
            }

            break;
        case 3:
            try {
                correct.setText(getContext().getString(R.string.nmean_alert) + "   " +Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("n_mean"))*100.0)/100.0);
                wrong.setText(getContext().getString(R.string.nmax_alert) + "   " +Math.round(Double.parseDouble(jsonArray.getJSONObject((int)(e.getX())).getString("n_max"))*100.0)/100.0);
            } catch (JSONException e1) {
                e1.printStackTrace();
            } catch (ParseException e1) {
                e1.printStackTrace();
            }

            break;
    }

    // this will perform necessary layouting
    super.refreshContent(e, highlight);

}

private MPPointF mOffset;

@Override
public MPPointF getOffset() {

    if(mOffset == null) {
        // center the marker horizontally and vertically
        mOffset = new MPPointF(-(getWidth()/2), -getHeight());
    }

    return mOffset;
}

}

最佳答案

我知道,有点晚了,但是:

mChart.highlightValue(null);

为我工作

10-08 13:45