Android load dialog box asynchronous execution implementation method

Source: Internet
Author: User

In Android, data is obtained through a sub-Thread to connect to the network, and the loading progress dialog box is displayed for the user's operations, which requires Thread and Handler to execute time-consuming code in the Thread, after completion, a message is sent to the main thread through Handler, And the UI is refreshed by the main thread.
The implementation is cumbersome. to simplify this method, it takes some time to encapsulate Thread and Handler. Now we can implement the same functions through simple code, put more energy into business logic processing!
Effect:
Copy codeThe Code is as follows: LoadingDialog loadingDialog = new LoadingDialog (getActivityGroup (), loadingDialogExecute );
// LoadingDialog. setIsShowDialog (false );
LoadingDialog. start ();
LoadingDialogExecute loadingDialogExecute = new LoadingDialogExecute (){
@ Override
Public void executeSuccess (){
// Update the UI, such as filling in the ListView
ListAdapter = new ListAdapter (MsgListActivity. this, wikis );
ListView. setAdapter (listAdapter );
}
@ Override
Public void executeFailure (){
// Processing when asynchronous execution fails or an error occurs
//......
}
@ Override
Public boolean execute (){
// Perform time-consuming operations here, such as pulling data from the connection network
Try {
//......
} Catch (Exception e ){
E. printStackTrace ();
SetErrorInfo ("error \ n" + e. getMessage ());
Return false;
}
Return true;
}
};
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.