Android - how to hide / show progressbar onclick

前端 未结 3 801
粉色の甜心
粉色の甜心 2021-01-28 22:52

I am trying to show a progressbar when a button is clicked. When i test the app it force closes / stops. My app works fine before the progressbar code is added in.

also

3条回答
  •  感情败类
    2021-01-28 23:14

    try following code...

    handler1 = new Handler()
    {
                @Override
                public void handleMessage(Message msg) 
                {
                    switch(msg.what)
                    {
                    case 1:
                        static_class.digi_pd = ProgressDialog.show(Create_Digitizing_Job.this, "Loading...", "Please Wait..", true,false);
                        static_class.digi_pd.setCancelable(false);
                        break;
                    case 2:
                        static_class.digi_pd.dismiss();
                        break;
    
                    }
                }
            };
    
            thread1 = new Thread()
              {
                    @Override
                    public void run()
                    {   
                           try
                            {  
    
    
                              handler1.sendEmptyMessage(1);
    
                        // write your code here....
    
                             handler1.sendEmptyMessage(3);
                             handler1.sendEmptyMessage(2);
    
                            } 
                           catch (Exception e) 
                           {
                               Log.w("thread error...",""+e);
                               //e.printStackTrace();
                           }   
    
                 }
    
             };
            thread1.start();
    

提交回复
热议问题