我如何制作 ProgressDialog,它会在我的方法做一些工作时显示?我知道有很多相关的问题,但我不明白答案。单独的线程是不是一个好方法?我的方法是从网上下载一些数据
请为我提供一个非常详细的答案,说明我如何做到这一点。单独的课程会很棒
任何答案和评论都将被应用
我如何制作 ProgressDialog,它会在我的方法做一些工作时显示?我知道有很多相关的问题,但我不明白答案。单独的线程是不是一个好方法?我的方法是从网上下载一些数据
请为我提供一个非常详细的答案,说明我如何做到这一点。单独的课程会很棒
任何答案和评论都将被应用
嘿,试试下面的代码,它可能会有所帮助:
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
new TheTask().execute();
 }
private class TheTask extends AsyncTask<Void, Void, Void>{
 @Override
protected void onPreExecute()
{
    super.onPreExecute();
    pDialog = new ProgressDialog(YOUR_ACTIVITY_CLASS_NAME.this);
    pDialog.setMessage("Please Wait");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
    authenticate(); // method that calls the API via SOAP
    authenticateReal(); // method that handles the response
    return null;
}
@Override
 protected void onPostExecute(String str)
 {
    // Dismiss the dialog once finished
    pDialog.dismiss();  
  }
 }
在调用它之前定义 pDialog:
   ProgresDialog pDialog;