I'm using Jsoup to get some weather data from wunderground.com and I want to plot it using the Graphview library for android. However, When I start my app, the weather data (via Jsoup) takes a few seconds to load since it's being scraped off the internet right then, and the graphview object expects the data as soon as the app is started in the onCreate method. What can I do so that graphview plots the data after Jsoup has scraped it? My onCreate mehtod looks like:
@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);
}
I think the issue here is how I get the weather data: I use AsyncTask, which gets weather data in the background and tries to run graphview in the foreGround. Anybody have an idea how to fix this? Thank you for helping. I am happy to post my AsyncTask if need be. I also tried running graphview from the my async class but without success.