Hi,
Use this code,

 new Thread(new Runnable() {
                 @Override
                 public void run() {
                    //GetWts(); //processes some action
                    try {
                        sleep(3000);
                    } catch (Exception e) {
                    // TODO: handle exception
                   }
                   handler.sendEmptyMessage(0);
                progressBar.dismiss();
                 }
           }).start();
          progressBar.dismiss();

           Handler handle=new Handler(){
                 @Override
                 public void handleMessage(Message msg) {
                       super.handleMessage(msg);
                       if(msg.what == 0) {
                         //perform some action here................
                       }
                 }
           };



On Feb 17, 3:59 pm, RLScott <[email protected]> wrote:
> I don't think progressBar.dismiss is appropriate when executed by a
> thread other than the main UI thread.  Use a handler to signal from
> the worker thread to the main UI thread and let the main UI thread do
> the actual messing with the UI.  The same goes for any other action
> that touches the UI directly.
>
> On Feb 16, 5:13 pm, dc <[email protected]> wrote:
>
>
>
>
>
>
>
> > I am attempting to show a progress dialog while I am performing some
> > actions. I am having troubles getting it to perform the way I would
> > like. Here is what I want to do:
> > click event of a button
> > pop up a progress dialog showing a busy message.
> > perform some action
> > then once the action is complete, inflate a new layout into my main
> > layout. (changing screens)
> > It works fine except either I inflate the layout while the other
> > actions are still processing (layout change is outside the thread) or
> > if I put the layout change in the thread, it forces a close of the
> > app, at the layout.removeallviews; line.
>
> > private OnClickListener feeAcceptListener = new OnClickListener() {
> >        @Override
> >       public void onClick(View v) {
> >           progressBar = ProgressDialog.show(v.getContext(), "Please
> > Wait...","Communicating",true);
> >            new Thread(new Runnable() {
> >                  @Override
> >                  public void run() {
> >                     GetWts(); //processes some action
> >                      progressBar.dismiss();
> >                  }
> >            }).start();
>
> >            Handler handle=new Handler(){
> >                  @Override
> >                  public void handleMessage(Message msg) {
> >                        super.handleMessage(msg);
>
> >                  }
> >            };
> >            LinearLayout layout =
> > (LinearLayout)findViewById(R.id.main_view);
> >            layout.removeAllViews();
> >            LayoutInflater inflater = getLayoutInflater();
> >            layout.addView(inflater.inflate(R.layout.wts, null));
>
> >            Button print = (Button)findViewById(R.id.btnPrintTic);
> >            Button done= (Button)findViewById(R.id.btnDone);
> >            print.setOnClickListener(wtsPrintListener);
> >            done.setOnClickListener(wtsDoneListener);
> >       }
> >     };

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to