如何在android中解析json解析中的有限记录

时间:2012-06-27 05:23:44

标签: android

我想做的第一件事就是在我的应用程序列表活动中添加一个进度对话框。活动并不耗时(不管怎样),但是当活动从json解析并嵌入到listactivity中时,您不希望UI无响应,给用户留下了不好的印象。 请帮帮我

1 个答案:

答案 0 :(得分:0)

使用AsyncTask在解析数据时显示进度对话框

private class DownloadingProgressTask extends
        AsyncTask<String, Void, Boolean> {

    private ProgressDialog dialog = new ProgressDialog(ShowDescription.this);

    /** progress dialog to show user that the backup is processing. */

    /** application context. */

    protected void onPreExecute() {
         this.dialog.setMessage("Please wait");
         this.dialog.show();

    }

    protected Boolean doInBackground(final String... args) {
        try {
            downloadFile(b.getString("URL"));
            return true;
        } catch (Exception e) {
            Log.e("tag", "error", e);
            return false;
        }
    }

    @Override
    protected void onPostExecute(final Boolean success) {

         if (dialog.isShowing()) {
         dialog.dismiss();
         }

        if (success) {
            Toast.makeText(ShowDescription.this,
                    "File successfully downloaded", Toast.LENGTH_LONG)
                    .show();
            //imgDownload.setVisibility(8);
        } else {
            Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG)
                    .show();
        }
    }

}