How to start and finish progressBar dynamically in android

前端 未结 4 858
刺人心
刺人心 2021-01-07 09:15

When I skip second activity class from first activity class, I will start imageprocessing on certain image in second activity and then until new image comes to screen I wnt

4条回答
  •  生来不讨喜
    2021-01-07 09:56

    Try using Async task as shown below:

    try{
    class test extends AsyncTask{
    
    
         TextView tv_per;
         int mprogress;
    
        Dialog UpdateDialog = new Dialog(ClassContext);
    
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            mprogress = 0;
    
            UpdateDialog.setTitle(getResources().getString(R.string.app_name));
            UpdateDialog.setContentView(R.layout.horizontalprogressdialog);
            TextView dialog_message =  (TextView)UpdateDialog.findViewById(R.id.titleTvLeft);
            tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
            dialog_message.setText(getResources().getString(R.string.dialog_retrieving_data));
            dialog_message.setGravity(Gravity.RIGHT);
            UpdateDialog.setCancelable(false);
            UpdateDialog.show();
            super.onPreExecute();
        }
    
    
    
        @Override
        protected void onProgressUpdate(Object... values) {
            // TODO Auto-generated method stub
            ProgressBar update = (ProgressBar)UpdateDialog.findViewById(R.id.horizontalProgressBar);
            update.setProgress((Integer) values[0]);
            int percent =  (Integer) values[0];
            if(percent>=100)
            {
                percent=100;
            }
            tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
             tv_per.setText(""+percent);
        }
    
    
    
        @Override
        protected Object doInBackground(Object... params) {
            // TODO Auto-generated method stub
            //your code
    }
    
            super.onPostExecute(result);
            UpdateDialog.dismiss();
        }
    
     }
     new test().execute(null);
    
     }
    catch(Exception e)
    {
     e.printStackTrace();
    }
    

提交回复
热议问题