我按照我认为可行的方式做这件事并没有太大的成功,所以我会问专家。
我有一个包含十个链接到图像的 URL 的 ArrayList。我想显示第一个 URL 2 秒,然后获取第二个 URL 并执行相同操作直到结束。
这是我到目前为止所拥有的,我想也许我不会以最好的方式通过 postExecute 中的对话框来处理它?:
private class LiveView extends AsyncTask<String, Integer, ArrayList<String>> {
ProgressDialog dialog;
private volatile boolean running = true;
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(
myView.this,
"Working",
"Info message . . .",
true,
true,
new DialogInterface.OnCancelListener(){
public void onCancel(DialogInterface dialog) {
cancel(true);
}
}
);
}
@Override
protected void onCancelled() {
running = false;
}
@Override
protected ArrayList<String> doInBackground(String... passed) {
while (running) {
//removed the code here that sends the request to to make this shorter the server but it works fine
return responseFromServer.arrayListofURLs; //list or URLs
}
return null;
}
@Override
protected void onPostExecute(ArrayList<String> listURLs) {
dialog.cancel();
Dialog liveView = new Dialog(myView.this, R.style.Dialog);
liveView.setContentView(R.layout.liveview_dialogue);
TextView title = (TextView)liveView.findViewById(R.id.liveViewTitle);
Button button = (Button) liveView.findViewById(R.id.liveViewButton);
ImageView trackImage = (ImageView)liveView.findViewById(R.id.liveViewImage);
//I want to loop through the ten images here?
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
liveView.show();
}
}