Display progress bar while loading

后端 未结 2 418
迷失自我
迷失自我 2021-01-16 20:16

I have one button in the main.xml which will link to another xml which include information from server. I include progress bar to avoid the blank screen while the system is

2条回答
  •  失恋的感觉
    2021-01-16 20:50

    Did you try Asyntask? Your doing process will be update in UI.

    public final class HttpTask
            extends
            AsyncTask {
    
        private HttpClient mHc = new DefaultHttpClient();
    
        @Override
        protected String doInBackground(String... params) {
            publishProgress(true);
            // Do the usual httpclient thing to get the result
            return result;
        }
    
        @Override
        protected void onProgressUpdate(Boolean... progress) {
            // line below coupled with 
            //    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS) 
            //    before setContentView 
            // will show the wait animation on the top-right corner
            MyActivity.this.setProgressBarIndeterminateVisibility(progress[0]);
        }
    
        @Override
        protected void onPostExecute(String result) {
            publishProgress(false);
            // Do something with result in your activity
        }
    }
    

提交回复
热议问题