如何显示此代码的 ProgressDialog?
try{
leggiNews = Pattern.compile("<p><a href='(.*?)' class='rossobig'>(.*?)</a><br/>(.*?)</p>");
leggi = leggiNews.matcher(getURL("http://www.example.com/"));
} catch(UnknownHostException tt){
Toast t=Toast.makeText(MainActivity.this, "NESSUNA CONNESSIONE DISPONIBILE!\nATTIVA LA RETE PER QUESTO SERVIZIO.", Toast.LENGTH_LONG);
t.setGravity(Gravity.TOP, 0, 240);
t.show();
}catch (Exception e) {
Toast t=Toast.makeText(MainActivity.this, "[ERRORE GENERICO!]\n"+e, Toast.LENGTH_LONG);
t.setGravity(Gravity.TOP, 0, 240);
t.show();
}
专门针对 getURL() 方法:
static final String getURL(String u)throws IOException {
URL url = new URL(u);
InputStream content = (InputStream) url.getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
String a="";
while ((line = in.readLine()) != null) {
a+=line;
}
in.close();
content.close();
return a;
}
getURL 方法始终在同一个类中,如何正确插入 ProgressDialog?谢谢你。