Java – a view in runonuithread

I'm making a custom ImageView One way is to load images from URLs And I want to retrieve the bitmap in a thread and load the bitmap in the UI thread

How do I make a runonuithread() call to draw a bitmap?

Are there any built-in features? Or should you create a handler in the constructor and use it in the UI thread to run runnable?

Solution

Download the image through asynctask and set it as your view with its onpostexecute method

or

Using view's post method from a separate image download thread, it will always run its runnable on the UI thread:

yourImageView.post(new Runnable() {
    @Override
    public void run() {
        // set the downloaded image here

    }
});
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>