0

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.

  • Yes post your asynch. The simplest way would be to get your data not in asynch or both of them in asynch. Why putting the graph creation in asynch didn't work? Did you get an error? – Alkis Kalogeris Dec 01 '13 at 19:43

1 Answers1

0

It turns out that I could make a graphview plot just by making a java method in my activity and invoking it from a click event or something similar. There isn't a need to put the grapview object in an Asynch class. I think this is correct, if not, feel free to contradict me.