简体   繁体   English

如何通过单击Android中的刷新按钮以新值更新饼图

[英]How to update a pie chart with new values by clicking a refresh button in android

How to update a pie chart with new values when I click a refresh button. 单击刷新按钮时如何使用新值更新饼图。

That means I want to remove old pie chart and create a new pie chart by clicking a button in the same activity.Here I am using A chart engine for displaying pie chart. 这意味着我想删除旧的饼图并通过在同一活动中单击一个按钮来创建新的饼图。在这里,我正在使用一个图表引擎来显示饼图。

Thanks in advance.. 提前致谢..

Call this code on the button click. 单击按钮时调用此代码。

Intent intent = getIntent();
finish();
//here you get new data for the pie chart.
startActivity(intent);

Basically you have to restart the activity, if you use the above code. 如果使用上述代码,则基本上必须重新启动活动。

Now if you can get data in a thread then try considering , AsyncTask and get the new data inside the doInBackground method. 现在,如果您可以在线程中获取数据,请尝试考虑AsyncTask并在doInBackground方法中获取新数据。 And after calling onPostExecute refresh the UI part making a new object display ie View in your case. 并在调用onPostExecute刷新UI部分,以显示新的对象,即您的情况下为View

You will have to remove the old data from your dataset and add the new values. 您将必须从数据集中删除旧数据并添加新值。 Once done this, just call mChartView.repaint() in order to do the visual refresh. 完成此操作后,只需调用mChartView.repaint()即可进行视觉刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM