开发者

Android:problem in displaying the progressbar dialog?

in my app i trying to display a progressbar for a time taken for a function to complete its execution and dismiss it after the function has completed its execution ...

my code definition is as follows :

 protected Dialog onCreateDialog(int id) {
        switch (id) {
            case PROCESS: {
                ProgressDialog dialog = new ProgressDialog(this);
                dialog.setTitle("Indeterminate");
                dialog.setMessage("Please wait while loading...");
                dialog.setIndeterminate(true);
                dialog.setCancelable(true);
                return d开发者_StackOverflowialog;
            }
        }
        return null;
    }




showDialog(PROCESS);
doFunction();
dismissDialog(PROCESS);

and for some reason the processdialog is not is not displayed...

can some one help me out here pls.... is there any other way to do it ...

thanks :)


Since your function takes some time to process, use an async task

new AsyncTask<Void, Void, Void>() {

        @Override
        protected void onPreExecute()
        {
             pd = ProgressDialog.show(getApplicationContext(),"", "Sending Image ...", true);
            Log.d(TAG, "onPreExecute()");
        }

        @Override
        protected Void doInBackground(Void... params)
        {
            doFunction();
            return null;
        }

        @Override
        protected void onPostExecute(Void res)
        {
            Log.d(TAG, "onPostExecute()");
            pd.dismiss();
        }
    }.execute();

Secondly setting it to indeterminate means you will only see a circle thingy.

You should set the progress style to STYLE_HORIZONTAL

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜