【问题标题】:Progess dialog while loading datas from internet [duplicate]从互联网加载数据时的进度对话框[重复]
【发布时间】:2013-02-15 21:23:55
【问题描述】:

我如何制作 ProgressDialog,它会在我的方法在工作时执行一些操作时显示?我知道有很多相关的问题,但我不明白答案。 单独的线程是不是一个好方法? 我的方法是从网上下载一些数据

请提供一个非常详细的答案,告诉我如何制作这个。 单独的课程会很棒

任何答案和评论都将得到应用

【问题讨论】:

  • 在问之前先做一点研究,如果你不介意?
  • 好的,我如何删除我的帖子?

标签: android progressdialog


【解决方案1】:

嘿,试试下面的代码,它可能会有所帮助:

  @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;

【讨论】:

  • 我将长期要做的事情放在哪里?
  • 如果我创建一个单独的类并将代码放在上面,我该如何实现它?对不起,noobish 问题
  • 实例化它之后,像这样调用doinbackground?
  • 在 doInBackground() 中做你的事情,你可以参考这个链接http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-22
  • 2019-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多