我AsyncTask
用来加载 adiv
中的 a WebView
,同时显示 a ProgressDialog
。内容已加载并ProgressDialog
显示,但它不会因为执行未进入而消失onPostExecute()
。你能告诉我我做错了什么吗?
package xx.xxx.xxx;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Document;
import android.R.string;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class NewsActivity extends Activity {
private WebView wView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_main);
new LoadNews().execute("");
}
private class LoadNews extends AsyncTask<String, Integer, String> {
private ProgressDialog Dialog = new ProgressDialog(NewsActivity.this);
@Override
protected String doInBackground(String... params) {
String url = "http://www.example.com/example";
Document doc;
try {
doc = Jsoup.connect(url).get();
Elements ele = doc.select("div#examplediv");
String html = ele.toString();
String mime = "text/html";
String encoding = "utf-8";
wView = (WebView)findViewById(R.id.wvNews);
wView.loadDataWithBaseURL(url, html, mime, encoding, null);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPreExecute()
{
Dialog.setMessage("please wait...");
Dialog.show();
}
protected void onPostExecute(Void unused)
{
try
{
if(Dialog.isShowing())
{
Dialog.dismiss();
}
} catch(Exception e) {
}
}
}
}