按照我认为可行的方式进行此操作并没有取得多大成功,所以我会请教专家。
我有一个包含十个链接到图像的 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();
}
}
最佳答案
创建一个处理程序,并通过 postDelayed 向其发送一条延迟 2 秒的消息。每当您收到消息时,通过调用 trackImage.setImage 显示下一张图像。当他们最终关闭对话框时,从处理程序中删除所有未决消息。
关于java - 在对话框中显示不断变化的图片循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15485383/