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