java - 在对话框中显示不断变化的图片循环?

标签 java android

按照我认为可行的方式进行此操作并没有取得多大成功,所以我会请教专家。

我有一个包含十个链接到图像的 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/

相关文章:

android - ViewPager Fragments 不显示正确的数据

android - 协程不断崩溃而不显示错误

android - 重置 Android Activity

java - java 中的 xmlSchema apache

java - 检查类类型

java - 在测试类中设置字段时出现 NullPointerException

android自定义组 View 布局不正确

java - Android 应用程序的启动可以动态控制或审查吗?

Java Seamframework - Restful URL - 如何?

java - 为什么方法 "setMaximumSize"不起作用,而 "setMinimumSize"却起作用?