我想顯示一個進度對話框在加載遠程服務器中的一些數據:顯示進度對話框在加載數據
我用下面的線程,以獲取數據和它的工作,但我不能夠在活動上顯示進度條:
public class Request {
public String text ;
public boolean downloadText(String urlStr) {
final String url = urlStr;
new Thread() {
public void run() {
int BUFFER_SIZE = 2000;
InputStream in = null;
Message msg = Message.obtain();
msg.what=2;
try {
in = openHttpConnection(url);
InputStreamReader isr = new InputStreamReader(in);
int charRead;
text = "";
char[] inputBuffer = new char[BUFFER_SIZE];
while ((charRead = isr.read(inputBuffer))>0)
{
//---convert the chars to a String---
String readString =
String.copyValueOf(inputBuffer, 0, charRead);
text += readString;
inputBuffer = new char[BUFFER_SIZE];
}
Bundle b = new Bundle();
b.putString("text", text);
msg.setData(b);
in.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
你能告訴我我該怎麼做!
首先,您的ProgressDialog代碼在哪裏?我沒有在上面的代碼中找到它。如果您要求在上述課程中實施,請查看我的答案。 – 2013-04-29 10:39:51