android中如何刷新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
是在另一个线程中接收到的字节数组。我想刷新图像视图..但它不起作用..它保留相同的默认图标
I want to refresh imageview
on bytearray received from socket.
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
图像要么始终出现相同的情况,要么只出现一次。
因为如果你从正确的地方正确触发了上面的代码,它必须刷新imageView。
尝试用不同的方式调试,刷新代码就可以了。
Either the image is coming same all the time, or it is coming only once.
Because if you have triggered the above code correctly from the right place, it must refresh the imageView.
Try to debug it in different manner, code to refresh is ok.
向大家抱歉。问题是上面的代码位于主线程中,因此阻塞了对 UI 的所有响应。
当我将代码从主线程移动到线程时,问题得到了解决。现在它可以正常工作了。
感谢所有回复
Sorry to all.The problem was that the above code was in the main thread,thus got blocking all responses to the UI.
The problem got solved when I moved the code to a thread from the main thread.Now it is working correctly.
Thanks for all replies