1Implementation Effect description:
1.1
DisplayLoading
1.2 after the question information is loaded, bind the question
1.3 loading failed, goLoading failed
2Asynchronous loading implementation
2.1Interface settings
Interface before loading
View Code
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "# ffffff"
Android: orientation = "horizontal"
>
<ProgressBar
Android: id = "@ + id/circleProgressBar"
Style = "? Android: attr/progressBarStyleLarge "mce_style = "? Android: attr/progressBarStyleLarge"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: visibility = "gone"
Android: max = "100"
Android: progress = "20"
/>
<TextView android: text = "loading information ..... "
Android: id = "@ + id/textView1"
Android: layout_width = "wrap_content"
Android: textColor = "#000000"
Android: layout_height = "wrap_content"> </TextView>
</LinearLayout>
Loading failure page
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "# ffffff"
Android: orientation = "horizontal"
>
<TextView android: text = "network exception, data cannot be loaded" android: id = "@ + id/textView1" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> </TextView>
<Button android: text = "reload" android: id = "@ + id/button1" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> </Button>
</LinearLayout>
2.2Create a custom asynchronous class
//AsyncTask class AsyncLoader_GuessInfo extends AsyncTask<String, Void, Integer>{ @Override protected Integer doInBackground(String... params) { int result=0; try{ gi=GuessDataServiceHelper.GetGuessInfo(params[0]); result=2; } catch(Exception ex){ result=-1; } return result; } }
2.3Call asynchronous classes,Different content is displayed based on the feedback.
View Code
/*
* Downloads question information.
**/
Private BegindownHandler mbegindownHandler = new BegindownHandler ();
Class BegindownHandler extends Handler {
@ Override
Public void handleMessage (Message msg ){
AsyncTask <String, Void, Integer> results = new asyncloader_guessinfo(cmd.exe cute (GuessNo );
Try {
If (results. get () = 2)
{
LoadAndBandingData (GuessNo );
}
Else
SetContentView (R. layout. async_error );
}
Catch (Exception ex)
{
SetContentView (R. layout. async_error );
}
}
Public void sleep (long delayMillis ){
This. removeMessages (0 );
SendMessageDelayed (obtainMessage (0), delayMillis );
}
};