这是我的代码。我已经在谷歌上搜索了大约 2 个小时,我快疯了。我一直在做与网站上所有示例完全相同的操作,但它不会显示,也不会给我任何错误。
我正在尝试在 asyncTask 中检索网站源,我想显示对话框屏幕,并在完成后将其关闭。
这是我的代码:
public static class RetrieveSiteData extends AsyncTask<String, Void, String> {
private Context SubContext;
private ProgressDialog pd;
public RetrieveSiteData(Context SubContext){
this.SubContext = SubContext;
}
@Override
protected void onPreExecute() {
pd = new ProgressDialog(this.SubContext);
pd.setTitle("Loading. Please wait...");
pd.show();
Log.v("Test","dit is het begin");
}
@Override
protected String doInBackground(String... urls) {
StringBuilder builder = new StringBuilder(1000000);
for (String url : urls) {
Log.v("URLS",url);
if(url != "" && url != null){
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = reader.readLine()) != null)
{
builder.append(line);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return builder.toString();
}
@Override
protected void onPostExecute(String result) {
pd.dismiss();
Log.v("Test","dit is het eind");
}
}