0

I have a list in my app that is populated via a http request to our database API. Then it parses the JSONArray that is returned, and sets the list appropriately. By the way I am quite new to Java coding and the eclipse environment.

I have achieved the http request with the custom library developed by loopj (located here)

However, when I go to the list in my app, it freezes for a second or two (while it collects the data) and then populates this list and everything works fine. Is it possible to implement a loader that will display until the list has completed loading with the current AsyncHttpClient I am using? Or do I need to change to a different one. I can't provide any code due to contractual agreements.

Thanks for any suggestions!

wh-dev
  • 537
  • 5
  • 18
  • 1
    Use [AsyncTask](http://developer.android.com/reference/android/os/AsyncTask.html) for your **AsyncHttpRequest**. – user370305 Jul 19 '12 at 09:44

1 Answers1

1

I do something like this in my Async class

public class Async extends AsyncTask {
    private ProgressDialog dialog;
    public Context applicationContext;

    @Override
    protected void onPreExecute() {
            //this should appear like a loading bar
        this.dialog = ProgressDialog.show(applicationContext, "Calling",
                "Update List ...", true);
    }

    @Override
    protected Object doInBackground(Object... params) {
            //call your method and threat response
        return SyncActivity.getUpdatedList();

    }

    @Override
    protected void onPostExecute(Object result) {
        this.dialog.cancel();
    }

}
cosmincalistru
  • 1,283
  • 9
  • 20
  • Thanks for your response. I used the AsyncTask given as an answer to [this question](http://stackoverflow.com/questions/3505930/make-an-http-request-with-android). How would I go about implementing your suggestion into it? I have put the onPreExecute into it, and also added the dialogue cancel call in the onPostExecute but it throws up some errors and crashes? – wh-dev Jul 19 '12 at 11:08
  • My suggestion is much the same as the one in the other post only that it adds the loading dialog and the treatment is not here but in other class. Sorry but not knowing the errors it throws i can't give more details. – cosmincalistru Jul 19 '12 at 11:45
  • Nevermind! I worked it out. the Context variable defined as applicationContext was coming back null. All sorted now though, thanks! – wh-dev Jul 19 '12 at 12:29