Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Asynctask在进度对话框后面显示圆圈_Android - Fatal编程技术网

Android Asynctask在进度对话框后面显示圆圈

Android Asynctask在进度对话框后面显示圆圈,android,Android,我想完全隐藏在下面的异步任务代码执行过程中显示的进度循环,同时显示进度对话框。问题是,可以通过透明的进度对话框看到圆圈。有人能帮忙吗?我不想改变进度对话框的透明度 new AsyncTask<String, Void, List<Product>>() { private ProgressDialog dialog; protected void onPreExecute() { this.dialog

我想完全隐藏在下面的异步任务代码执行过程中显示的进度循环,同时显示进度对话框。问题是,可以通过透明的进度对话框看到圆圈。有人能帮忙吗?我不想改变进度对话框的透明度

    new AsyncTask<String, Void, List<Product>>() {

        private ProgressDialog dialog;

        protected void onPreExecute() {
            this.dialog = ProgressDialog.show(getActivity(), "Progress", "Retrieving products...", false, false);
        }

        protected void onPostExecute(List<Product> result) {
            // populate the list
            Context context = getSherlockActivity().getApplicationContext();
            ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(context, R.layout.productlist_item, result);
            setListAdapter(adapter);

            // dismiss the progress dialog
            dialog.dismiss();
        }

        @Override
        protected List<Product> doInBackground(String... params) {
            // populate the database if required
            try {
                // get the data from the server
                MyApplication.populateProductDatabase(false);
            } catch (NotConnectedToInternetException e) {
                exceptionMessage = "Unable to retrieve data. Internet connection unavailable.";
                e.printStackTrace();
            }

            // get the records in the database
            ProductDAO dao = new ProductDAO();
            List<Product> result = dao.getProducts(params[0]);

            return result;
        }
    }.execute(find);

我还看到了一些奇怪的对话框后面的正常一个与您的代码。尝试创建一个单独的AsyncTask类

比如:

private class MyAsyncTask extends AsyncTask<String, Void, List<Product> {

    private Activity mActivity;
    private ProgressDialog mDialog;

    public MyAsyncTask(){

        this.mActivity = MyActivity.this;
        mDialog = new ProgressDialog(mActivity);

    }

    protected void onPreExecute() {
        mDialog.setMessage("Retrieving products...");
        mDialog.show();
    }

    protected void onPostExecute(List<Product> result) {
        // populate the list
        Context context = getSherlockActivity().getApplicationContext();
        ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(context, R.layout.productlist_item, result);
        setListAdapter(adapter);

        // dismiss the progress dialog
        mDialog .dismiss();
    }

@Override
    protected List<Product> doInBackground(String... params) {
        // populate the database if required
        try {
            // get the data from the server
            MyApplication.populateProductDatabase(false);
        } catch (NotConnectedToInternetException e) {
            exceptionMessage = "Unable to retrieve data. Internet connection unavailable.";
            e.printStackTrace();
        }

        // get the records in the database
        ProductDAO dao = new ProductDAO();
        List<Product> result = dao.getProducts(params[0]);

        return result;
    }
}

我已经找到了这个问题的原因:事实上ListFragment的ListAdapter尚未设置。解决方案是将ListAdapter设置为空列表,这会告诉ListFragment它有它的结果,并且没有进行其他处理

通过向onCreate方法添加以下两行代码,问题得以解决

ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(getActivity(), R.layout.productlist_item, new ArrayList<Product>());
setListAdapter(adapter);

你说的进步圈到底在哪里?我无法理解你的问题。进度圈就出现在我的进度对话框后面。如果我完全删除了进度对话框代码,进度圈仍然会出现。在创建/初始化进度圈的位置发布相关java代码或布局xml。我不是有意创建进度圈,因此没有xml。当我调用上面的代码时,它神奇地出现了。不幸的是,这不起作用。我在进度对话框后面还有一个奇怪的对话框。你从哪里叫你的AsynTask?单击按钮?不,我是从ListFragment上的onCreateBundle savedInstanceState方法执行的
ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(getActivity(), R.layout.productlist_item, new ArrayList<Product>());
setListAdapter(adapter);