SoFunction
Updated on 2025-03-11

Detailed explanation of the usage of Android Custom ProgressDialog ProgressBar Dialog

<span style="">package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class SecondActivity extends Activity implements Runnable{
/**
* Called when the activity is first created.
* Activity entrance
* */
private Button b_dialog,b_dialog1,button;//Two buttons
private ProgressDialog pd,pd1;//Progress bar dialog box
private int count;
public void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView();//Associate the corresponding interface
b_dialog = (Button)(.button_dialog);
b_dialog1 = (Button)(.Button_dialog1);
//What to do when handling events occur
b_dialog.setOnClickListener(listener);
b_dialog1.setOnClickListener(listener);
</span>
<span style=""> }
//Define the listener object
private OnClickListener listener = new OnClickListener() {
// After pressing the mouse
public void onClick(View v) {
// Get the ID of the currently triggered event - the type is int
int id = ();
if(id == .button_dialog){
//The process dialog box will disappear when pressing the OK key
// pd = new ProgressDialog();// Create a ProgressDialog object
// (ProgressDialog.STYLE_SPINNER);// Set the progress bar style, the style is circled and rotated
// ("Tip");// Set ProgressDialog title
// ("This is a circular progress bar dialog");// Set ProgressDialog prompt information
// ();// Set ProgressDialog title icon
// // Set whether the progress bar of ProgressDialog is unclear or not false is not set to unclear
// (false);
// (true); // Set ProgressDialog to cancel if you can press the return key
// ("OK", new Bt1DialogListener()); // Set a Button of ProgressDialog
// (); // Let ProgressDialog display
//The process dialog box will disappear by itself after 1 second
// Another dialog box pops up
pd = (, "Automatically close the dialog box", "Working,,,,,1 second", true, false);
Thread thread = new Thread();//Open a thread to delay
();//Start the thread
}else if(id == .Button_dialog1){
pd1 = new ProgressDialog();// Create ProgressDialog object
(ProgressDialog.STYLE_HORIZONTAL);// Set the progress bar style, the style is circled and rotated
("Tip");// Set ProgressDialog title
("This is a bar progress bar dialog");// Set ProgressDialog prompt information
();// Set ProgressDialog title icon
// Setting the progress bar of ProgressDialog is unclear whether it is unclear.
(false);
(true); // Set ProgressDialog to cancel if it can be pressed to return
(100);// Set ProgressDialog Progress Bar
(); // Let ProgressDialog display
count = 0;
new Thread() {
public void run() {
try {
while(count <= 100) {
// The progress is controlled by the thread
(count++);
(100);
}
();
} catch (Exception e) {
();
}
}
}.start();
}
}
};
//Run is the implementation
public void run() {
try {
(1000);//Sleep for 1 second
} catch (InterruptedException e) {
();
}
(0);//Send message
}
//Define the object to process the message
private Handler handler = new Handler(){
//Join and send messages, just do it like this
public void handleMessage(Message msg){
();//The dialog box disappears
(, "The dialog box disappears", 3).show();
}
};
// The listener class of pdButton01
class Bt1DialogListener implements {
@Override
public void onClick(DialogInterface dialog, int which) {
// Click the "OK" button to cancel the dialog box
();
}
}
}
</span>