我有一个MarkerView
类,看起来像这样:
public class InfoMarkerView extends MarkerView {
TextView tv;
LineChart mChart;
public InfoMarkerView(Context context, int layoutResource, LineChart chart) {
super(context, layoutResource);
mChart = chart;
}
@Override
public void refreshContent(Entry e, Highlight highlight) {
tv = (TextView) findViewById(R.id.textView6);
tv.setText("Marker set in refreshContent");
MyBackgroundTask myTask = new MyBackgroundTask(this); //extends AsyncTask
myTask.execute();
}
//callback from MyBackgroundTask
public void myBackgroundTaskFinished(BackgroundTaskResult r) {
tv.setText("Marker changed in myBackgroundTaskFinished");
mChart.invalidate(); //doesn't really seem to change anything
}
调用回调后,TextView
被成功更新(我可以在观察窗口中看到),但在图表界面中看不到更改。我遗漏了什么?如何刷新TextView
看起来refreshContent()
不仅在每次用户突出显示图表中的点(如我所假设的)时被执行,而且在移动和与图表交互时也被执行。这为图表中的同一点创建了多个更新,因此,竞争条件- refreshContent()
在后台任务执行后立即将值更新回初始值,并且从未看到值更改。
现在我正在跟踪X值被更新,如果它没有改变,我不更新它:
public void refreshContent(Entry e, Highlight highlight) {
if (e.getX() == mLastRefreshedX) return;
...