我正在使用 Jsoup 从 wunderground.com 获取一些天气数据,我想使用 Graphview 库为 android 绘制它。但是,当我启动我的应用程序时,天气数据(通过 Jsoup)需要几秒钟才能加载,因为它正在从互联网上被刮掉,并且一旦应用程序在 onCreate 方法中启动,graphview 对象就会期望数据。在 Jsoup 抓取数据之后,我该怎么做才能让 graphview 绘制数据?我的 onCreate 方法看起来像:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new getWeather().execute();
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(0, weatherData[0])
, new GraphViewData(1, weatherData[1])
, new GraphViewData(2, weatherData[2])
});
GraphView graphView = new BarGraphView(this , "Weather Graph" );
graphView.addSeries(exampleSeries); // data
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(graphView);
}
我认为这里的问题是我如何获取天气数据:我使用 AsyncTask,它在后台获取天气数据并尝试在前台运行 graphview。有人知道如何解决这个问题吗?感谢您的帮助。如果需要,我很乐意发布我的 AsyncTask。我还尝试从我的异步类运行 graphview,但没有成功。