gpt4 book ai didi

android - 如何删除或隐藏 MPAndroidChart 中的 MarkerView?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:07 56 4
gpt4 key购买 nike

我用 MPAndroidChart 做了条形图.我做了一个自定义标记 View 类来查看条形图的值。
几秒钟后我会删除或隐藏 View 。它应该作为 toast 。但是我做不到。
这首先是一个问题,因为在我第一次触摸图表后,它变得可见,只有当我找到正确的点击条件时它才会消失。

有人知道怎么解决这个问题吗?

在我的代码中我有:

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

我的 CustomMarkerView 是

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);

为我工作

关于android - 如何删除或隐藏 MPAndroidChart 中的 MarkerView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43738763/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com