0

我想使用进度条将数据从列表加载到具有加载效果的gridview。我从webservice获取项目。我面临的问题是即使在显示gridview之后我也无法关闭进度条。我可以看到带有项目的gridview但是进度条仍在运行。我在这里做错了什么。

private void testAsyncTask() {
        Log.e("Im in testAsyncTask()", "");
        new AsyncTask<Object, Object, Object>() {

            @Override
            protected void onPreExecute() {

                progress_Dialog = ProgressDialog.show(a, "", "Loading");


                Log.e("Im in onPreExecute", "");
                // super.onPreExecute();
            }

            @Override
            protected Integer doInBackground(Object... params) {
                MenuService menuService = new MenuServiceImpl();
                PartnerMenuServiceResponse partnerMenu = menuService
                        .getPartnerMenu();
                jewellist = partnerMenu.getMenu().getMenuEntries();
                Log.e("Im in doInBackground", "");
                System.gc();

                return 0;
            }

            @Override
            protected void onPostExecute(Object result) {
                // TODO Auto-generated method stub
                // super.onPostExecute(result);asd
                Log.e("Im in onPostExecute", "");
                 if (progress_Dialog.isShowing()) {
                     progress_Dialog.dismiss();
                    }
                 ShopGridAdapter adapter = new ShopGridAdapter(ShopGridActivity.this, jewellist);
                 AllJewelgridView.setAdapter(adapter);
                    adapter.notifyDataSetChanged();

                //AllJewelgridView.setAdapter(new ShopGridAdapter(
                    //  ShopGridActivity.this, jewellist));

                if (AllJewelgridView.getCount() <= 0) {
                    MyAlertDialog.ShowAlertDialog(ShopGridActivity.this, "",
                            "No data found.", "OK");
                }
                progress_Dialog.dismiss();
            }

        }.execute();

    }
4

3 回答 3

2
@Override
protected void onPreExecute() {
    progress_Dialog = new ProgressDialog(context);
    progress_Dialog.setMessage("Loading...");
    progress_Dialog.show();
}

编辑 :

@Override
protected void onPostExecute(Object result) {
    Log.e("Im in onPostExecute", "");     <------ ARE YOU ABLE SEE THIS IN logcat ?
    progress_Dialog();
}

可能没有调用 onPostExecute()。所以要确认检查logcat

于 2012-09-07T09:09:37.907 回答
1

你需要在你的AsyncTask

 ProgressDialog progress=null;
progress=ProgressDialog.show(this,"title","loading..").show();//put this code in onPreExecute()
progress.dismiss();//put this code in onPostExecute()

加载 ListView 时获取更多ProgressBar(使用 AsyncTask)

于 2012-09-07T09:17:00.177 回答
0

您可以编写 onPostExecute 方法可能对您有所帮助。

 if ( progress_Dialog != null) {
             progress_Dialog.cancel();
        }
于 2012-09-07T09:21:42.937 回答