Android - Create Progress Dialog

前端 未结 1 1042
萌比男神i
萌比男神i 2021-01-15 18:30

I am new to android development. I want to develop a dialog with a progressbar in my application. When i click the search button the dialog

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 18:57

    Use a ProgressDialog. You should do the work on a new thread, though, and use a handler to call back to the activity when finished. Here's how I do it:

    private ProgressDialog pd;
    
    private View.OnClickListener searchClick = new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
            pd = ProgressDialog.show(MyActivity.this, "Searching...", "Searching for matches", true, false);
            new Thread(new Runnable() {
                    public void run() {
                        //do work
                    //.....
    
                    finishedHandler.sendEmptyMessage();
                    }
                }).start();
        }
    }
    
    private Handler finishedHandler = new Handler() {
        @Override public void handleMessage(Message msg) {
            pd.dismiss();
            //start new activity
        }
    }
    

    0 讨论(0)
提交回复
热议问题