问题
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
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/8703407/how-to-refresh-imageview-in-android