如何刷新安卓的ImageView [英] How to refresh imageview in android

查看:1863
本文介绍了如何刷新安卓的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要刷新从插座收到的ImageView 字节组上

new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                while (!socket.isClosed()) {
                    imgArray = receiveImagebytes();
                }
            }
        }).start();

        try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


while (!socket.isClosed()) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    imageView.setImageBitmap(BitmapFactory.decodeByteArray(imgArray, 0, imgArray.length));
                    imageView.invalidate();
                }
            });

imgArray 是在另一个线程收到的ByteArray。我想刷新它不working..It与相同的默认图标剩余imageview..But

imgArray is the bytearray received in another thread. I want to refresh the imageview..But it is not working..It is remaining with same default icon

推荐答案

抱歉all.The的问题是,上述code是在主线程,从而阻止了所有响应的用户界面。

Sorry to all.The problem was that the above code was in the main thread,thus got blocking all responses to the UI.

问题得到有效解决,当我的移动code,从主线程。现在它是否正常工作。

The problem got solved when I moved the code to a thread from the main thread.Now it is working correctly.

感谢所有答复

这篇关于如何刷新安卓的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆