0
public void generateNumbers(){
    progressBar.setVisibility(View.VISIBLE);

    while(){
        //approximately 5 second long procedure
    }
    printNumbers();
    progressBar.setVisibility(View.GONE);
}

I want that the progress bar is visible when this long procedure in while loop is running and then dissapear. The code like this shown progressBar after the loop is finished and then also dissapear (setVisiblity(GONE)).

In while loop i don't have any new threads or AsyncTask

4

1 回答 1

1

使用这样的异步任务

    public class asyncTask extends AsyncTask<String, Void, String> {

        private Context context;
        private ProgressDialog dialog;

        public asyncTask(Context cxt) {
            context = cxt;

            dialog = new ProgressDialog(context);
        }



        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

            dialog.setTitle("Please Wait...");
            dialog.show();



        }


        @Override
        protected void onPostExecute(String result) {
            dialog.dismiss();
        }

        @Override
        protected String doInBackground(String... arg0) {

            //Put your code here 
             }

}
于 2013-07-05T12:56:44.260 回答