AsyncHttpRequest的Android加载屏幕

问题描述:

我的应用程序中有一个列表,该列表通过对数据库API的http请求填充。然后它解析返回的JSONArray,并适当地设置列表。顺便说一下,我对Java编码和eclipse环境相当陌生。AsyncHttpRequest的Android加载屏幕

我已经实现了与循环J(位于here)开发的自定义库

然而,当我去我的应用程序列表中的http请求,冻结了一两秒钟(同时收集数据),然后填充这个列表,一切工作正常。是否有可能实现一个加载器,将显示,直到列表完成加载与我使用的当前AsyncHttpClient加载?或者我需要改变一个不同的。由于合同协议,我无法提供任何代码。

感谢您的任何建议!

+1

使用[的AsyncTask(http://developer.android.com/reference/android/os/AsyncTask.html)为您的** AsyncHttpRequest * *。 – user370305 2012-07-19 09:44:42

我做这样的事情在我的异步类

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(); 
    } 

} 
+0

感谢您的回复。我用AsyncTask给出了[这个问题]的答案(http://stackoverflow.com/questions/3505930/make-an-http-request-with-android)。我将如何去实施你的建议?我已经将onPreExecute放入它,并在onPostExecute中添加了对话取消调用,但它引发了一些错误和崩溃? – 2012-07-19 11:08:12

+0

我的建议与其他文章中的建议非常相似,只不过它增加了加载对话框,治疗不在这里,而是在其他类中。对不起,但不知道它抛出的错误,我不能给出更多的细节。 – cosmincalistru 2012-07-19 11:45:56

+0

没关系!我解决了它。定义为applicationContext的Context变量返回null。现在所有排序,谢谢! – 2012-07-19 12:29:10