本文介绍了如何使用处理程序可运行的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,我有一个问题,我想与功能的处理器可运行的形象,但我失败,
像什么C $ C $到可运行的图像上这个code?可以帮我解决这个问题?

 意向意图= getIntent(); 字符串URL = intent.getStringExtra(URL);
tombol2 =(按钮)findViewById(R.id.button2);IV =(ImageView的)findViewById(R.id.imageView1);
可绘制D1 = LoadImageFromWebOperations(URL);
iv.setImageDrawable(D1);}
私人绘制对象LoadImageFromWebOperations(字符串URL)
        {
             尝试
             {
                 InputStream为=(InputStream的)新的URL(网址).getContent();
                 可绘制D = Drawable.createFromStream(是,SRC名);
                 返回D组;
        }赶上(例外五){
                 的System.out.println(EXC =+ e)条;
                 返回null;
             }
        }
   }


解决方案

它固定的,只是LoadImageWebOperations之前给这个可运行

 可运行=新的Runnable(){        @覆盖
        公共无效的run(){
            尝试{
                LoadImageFromWebOperations(D1);
            }赶上(例外五){
                e.getStackTrace();
            }
            新的处理程序()postDelayed(可运行,10000);
        }
    };
    新的处理程序()postDelayed(可运行,10000);
}

i am newbie and i have a question, i want to runnable image with function handler, but i am failure,like what code to runnable image on this code ? can help me with this problem ?

Intent intent = getIntent();

 String url= intent.getStringExtra("URL");
tombol2 = (Button) findViewById(R.id.button2);

iv = (ImageView) findViewById(R.id.imageView1);
Drawable d1=LoadImageFromWebOperations(url);
iv.setImageDrawable(d1);

}
private Drawable LoadImageFromWebOperations(String url)
        {
             try
             {
                 InputStream is = (InputStream) new URL(url).getContent();
                 Drawable d = Drawable.createFromStream(is, "src name");
                 return d;
        }catch (Exception e) {
                 System.out.println("Exc="+e);
                 return null;
             }
        }
   }
解决方案

It fixed, just give this runnable before LoadImageWebOperations

runnable = new Runnable() {

        @Override
        public void run() {
            try {
                LoadImageFromWebOperations(d1);
            } catch (Exception e) {
                e.getStackTrace();
            }
            new Handler().postDelayed(runnable, 10000);
        }
    };
    new Handler().postDelayed(runnable, 10000);
}

这篇关于如何使用处理程序可运行的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 23:50