开发者

why my android application become slow in running?

I'm using this code to display severl images from the internet

ImageView iv = new ImageView;
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
iv.setImageDrawable(d)

but the application became开发者_StackOverflow中文版 slow in running why ?? does the internet connection is the reason ??? or because i input several input stream to display each image???


You should create the InputStream and Drawable.createFromStream(...) asynchronously, either using an AsyncTask or using a separate thread and then update the ImageView using a Handler once they are complete. AsyncTask is prefereable.

http://developer.android.com/reference/android/os/AsyncTask.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜