Reputation:
In my code below, I want a spinner style process dialog for 5 seconds after the user clicks "Check For Root". Basically after the user hits the button, the process dialog will say "Please wait..." for 5 seconds and then display the results. How do I do that ? Please help!
Button Root = (Button) findViewById(R.id.Root);
Root.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (RootTools.isAccessGiven()) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Congratulations!");
builder.setMessage("You Have Root Access!");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Oops!");
builder.setMessage("No Root Access!");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
Upvotes: 0
Views: 362
Reputation: 9700
private Handler mTimerHandler = new Handler();
private ProgressDialog mProgressDialog = null;
private Button Root;
@Override
protected void onCreate(Bundle savedInstanceState) {
...........
Root = (Button) findViewById(R.id.Root);
Root.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mProgressDialog = ProgressDialog.show(MainActivity.this, "", "Please wait...", true);
mTimerHandler.postDelayed(mTimerExecutor, 5000);
}
});
...........
}
private Runnable mTimerExecutor = new Runnable() {
@Override
public void run() {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
showDialog();
}
};
private void showDialog() {
if (RootTools.isAccessGiven()) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Congratulations!");
builder.setMessage("You Have Root Access!");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Oops!");
builder.setMessage("No Root Access!");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
Upvotes: 1
Reputation: 484
You can use Jquery loader for this purpose. Find Jquery loader JS and Jquery CSS and include them in you application.
write this code on page load
$.loader({
className:"blue-with-image-2",
content:''
});
write this after the query or process is completed:
$.loader('close');
This closes the loader after the process is done. You can place some text instead of loader also. Hope this helps
Upvotes: 0
Reputation: 2200
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen_layout);
ProgressDialog progressDialog;
progressDialog = new ProgressDialog(BrandList.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.show();
Thread thread = new Thread() {
@Override
public void run() {
try {
synchronized (this) {
wait(5000); // the time in millis.
}
} catch (InterruptedException e) {
} finally {
progressDialog.dismiss();
//do your stuff.
}
}
};
thread.start();
}
Upvotes: 0