1. ProgressDialog
ProgressDialog and ProgressBar dynamically display a loading icon in the UI to display the program running status.
ProgressDialog is inherited from the designed interactive dialogue window. When using it, a new ProgressDialog object must be created. A "dialog box" will pop up as a reminder when it is run. At this time, the application background loses focus (that is, it is impossible to operate on the UI components). The control will not be handed over to the application until the process is over. If you do not want the background to be out of focus in the Activity, and you also want to prompt the User that a background program is in a busy stage, then ProgressBar will come in handy.
ProgressDialog mProgressDialog = new ProgressDialog();
// Set mProgressDialog style
(ProgressDialog.STYLE_SPINNER);//Circular
(ProgressDialog.STYLE_HORIZONTAL);//Horizontal
// Set mProgressDialog title
("hint");
// Set mProgressDialog prompt
("This is a circular progress bar dialog");
// Set the mProgressDialog progress bar icon
();
// Set the progress bar of mProgressDialog is unclear
//When not scrolling, the current value moves between the minimum and maximum values. Generally, when performing some tasks that cannot determine the operation time, it is a prompt. When it is clear, the current progress value can be set according to your progress.
(false);
//(m_count++);
// Can I press the rollback key to cancel
(true);
// Set a Button of mProgressDialog
("OK", new ()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
();
}
});
// show();
(new () {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
();
();
}
});
When there is a ProgressDialog, when you click back, the ProgressDialog will be cancelled first. The above code can listen to the cancellation event of the progress bar (that is, click the Back key to cancel the ProgressDialog). At this time, some processing to cancel the background operation can be done here.
2. ProgressBar
Important XML attributes
android:progressBarStyle: default progress bar style
android:progressBarStyleHorizontal:horizontal style
Important Methods
getMax(): Returns the upper limit of the range of this progress bar
getProgress(): Return progress
getSecondaryProgress(): Returns secondary progress
incrementProgressBy(int diff): Specify the incremented progress
isIndeterminate(): Indicates whether the progress bar is in uncertain mode
setIndeterminate(boolean independence): Set in uncertain mode
setVisibility(int v): Set whether the progress bar is visible
Important Events
onSizeChanged(int w, int h, int oldw, int oldh): This event is raised when the progress value changes
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome to blog" />
<ProgressBar
android:
style="?android:attr/progressBarStyleHorizontal" mce_style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<ProgressBar
android:
style="?android:attr/progressBarStyleLarge" mce_style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button android:
android:text="Show ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>