【发布时间】:2013-04-22 22:59:24
【问题描述】:
我想在从远程服务器加载一些数据时显示一个进度对话框:
我正在使用以下线程来获取数据并且它正在工作,但我无法在活动中显示进度条:
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 代码在哪里?我没有在上面的代码中找到它。如果您要求在上述课程中实现,请查看我的答案。