I have a class that extends Runnable. This class does the hard work (basically uploads the image from the network) to another thread. I want to update the interface (display the loaded image on ImageView) from this class. I tried using a handler but could not. Here is my code:
class DataReceiver implements Runnable
{
public Bitmap bmp;
Public Handler uiHandle;
@Override
public void run()
{
while(true)
{
}
}
}
In the main action
ImageView img = (ImageView)findViewById(R.id.dispImg);
DataReceiver dr=new DataReceiver();
Handler uiHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
updateUI();
}
}
dr.uiHandle = uiHandler;
(new Thread(dr)).start();
pubic void updateUI()
{
img.setBitmap(dr.bmp);
}
Is it the right method to update an interface?
source
share