2017-02-27 88 views
-1

我新的Android開發人員,我上的AsyncTask工作,我想需要的進展原生廣告的對話框是這樣的:的AsyncTask定製progressdialog

enter image description here

我使用XML佈局,但不能顯示,如果任何機構知道請指導我實施。 這怎麼可能?請幫幫我。

enter image description here

我的代碼:

private class AsyncTaskRunner extends AsyncTask<String, String, String> { 
    private String resp; 
    ProgressDialog progressDialog; 

    View customProgress; 

    @Override 
     protected String doInBackground(String... params) { 
     publishProgress("Sleeping..."); // Calls onProgressUpdate() 
     try { 
      int time = Integer.parseInt(params[0]) * 1000; 

      Thread.sleep(time); 
      resp = "Slept for " + params[0] + " seconds"; 
     } 
     catch (InterruptedException e) { 
      e.printStackTrace(); 
      resp = e.getMessage(); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
      resp = e.getMessage(); 
     } 
     return resp; 
    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.os.AsyncTask#onPostExecute(java.lang.Object) 
    */ 
    @Override 
     protected void onPostExecute(String result) { 
     // execution of result of Long time consuming operation 
     finalResult.setText(result); 
     progressDialog.dismiss(); 
    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.os.AsyncTask#onPreExecute() 
    */ 
    @Override 
     protected void onPreExecute() { 
     progressDialog = new ProgressDialog(MainActivity.this); 
     progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.ic_launcher)); 
     progressDialog.setCancelable(false); 
     progressDialog.setMessage("Downloading! Please wait...!" + time.getText().toString() + " seconds"); 

     progressDialog.show(); 
    } 
} 

回答

相關問題