How to refresh image view immediately

后端 未结 4 490
情书的邮戳
情书的邮戳 2020-12-10 03:49

In my android app, I download an image from the cloud. The download is performed in a thread and in that same thread I also set an image view with the newly downloaded image

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 04:16

    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();
                    }
                });
    

提交回复
热议问题