我正在进行延迟加载并几乎完成了它。但是想要实现一个进度对话框,因为在开始活动和完成显示内容之间需要大约10秒。一旦我点击一个按钮开始,它将停留在当前页面(Main.java)约4秒钟,然后移动到下一页面(Activity.java)。然后显示内容大约需要2-4秒钟。Android - 单击按钮后右键单击显示进度对话框
尝试了这里和网上可用的例子,但它们工作不正常(能够显示对话框,但在内容全部下载后无法做适当的解雇)。
问题是,一旦用户点击按钮,我该如何立即实现一个进度指示器?
Activity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(this, mStrings, dStrings);
list.setAdapter(adapter);
}
private String[] mStrings = {};
private String[] dStrings = {};
public Activity()
{
String imageC = "";
String textC = "";
try {
// Get the URL from text box and make the URL object
URL url = new URL(targetURL);
// Make the connection
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line = reader.readLine();
Pattern sChar = Pattern.compile("&.*?;");
Matcher msChar = sChar.matcher(line);
while (msChar.find()) line = msChar.replaceAll("");
while (line != null) {
if(line.contains("../../"))
{
int startIndex = line.indexOf("../../") + 6;
int endIndex = line.indexOf(">", startIndex + 1);
String abc = "http://www.petschannel.com/";
String imageSrc = line.substring(startIndex,endIndex);
//complete full url
String xyz = abc +imageSrc;
xyz = xyz.substring(0,xyz.indexOf('"'));
xyz = xyz +";";
imageC += xyz;
mStrings = imageC.split(";");
line = reader.readLine();
}
if(line.contains("../../") == false)
{
line = reader.readLine();
}
if (line.contains("Gnametag"))
{
int startIndex = line.indexOf("Gnametag") + 10;
int endIndex = line.indexOf("<", startIndex + 1);
String gname = line.substring(startIndex,endIndex);
textC += "Name: "+gname+ "\n";
}
if (line.contains("Last Update"))
{
reader.close();
}
}
// Close the reader
reader.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
那么我的情况建议什么?我尝试创建一个私人字符串[]。然后将方法更改为void。但它没有运行该方法。我需要通过使用AsyncTask来完成什么?打电话给我的方法?谢谢 – Hend