0

AsyncTaskの実行中に表示される進行状況サークル(以下のコード)を完全に非表示にし、進行状況ダイアログを表示したいと思います。問題は、透明な進行状況ダイアログを通して円が見えることです。誰かが助けることができますか?[進行状況]ダイアログの透明度を変更したくない...

    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);
4

2 に答える 2

0

この問題の原因を突き止めました。それは、ListFragment の ListAdapter がまだ設定されていないという事実です。解決策は、ListAdapter を空のリストに設定することです。これにより、ListFragment に結果があり、他の処理が行われていないことが通知されます。

onCreate メソッドに以下の 2 行を追加することで問題が解決しました。

ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(getActivity(), R.layout.productlist_item, new ArrayList<Product>());
setListAdapter(adapter);
于 2012-06-30T01:46:25.663 に答える
0

また、あなたのコードで通常のダイアログの背後にある奇妙なダイアログも見ました。代わりに、別の 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;
    }
}

そして、次のように呼び出します。

MyAsyncTask asyncTask = new MyAsyncTask();
                 asyncTask .execute();
于 2012-06-24T22:18:08.710 に答える