The android sub-thread updates the UI and works with the main thread.

Source: Internet
Author: User

In the past few days, the development process involves a program that dynamically refreshes the UI. The refreshing process is executed by opening up a new thread, however, the results were not tested during the operation. After tracing and debugging the program, we found that the main interface had not been refreshed. After some tossing, we found that the main thread must be notified to update through the handler component. Here is a simple example to illustrate that if you have any questions, you can leave a message to me.

Handler homeachandler = new handler (){
Public void handlemessage (Message MSG)
{
Myimageview = NULL;
If (msg. What = 0)
{
Log. D (log_tag, "Has recive MSG ");
Synchronized (locationinfo. loc_object ){
For (INT I = 0; I <arraylist. Size (); I ++ ){
Int location_x, location_y;
Location_x = (INT) locationinfo. neighbourcollectionfinal. Get (I). X;
Location_y = (INT) locationinfo. neighbourcollectionfinal. Get (I). Y;
Myimageview = new myimageview (XX. This, 150,50, 0.2f, 0.5f, 0.1f, 0.6f );
Myimageview. setimageresource (R. drawable. stars_woman );
Mmyimageviewlist. Add (myimageview );
}
}
For (INT I = 0; I <mmyimageviewlist. Size (); I ++)
{
Mstarsrealtivelayout. addview (mmyimageviewlist. Get (I); // Add to interface
}
Mmyimageviewlist. Clear (); // clear
}
}
}

Source: eyeandroid

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.