在我的下面的代码中,在用户单击“Check For Root”后,我想要一个微调器样式进程对话框,持续5秒。基本上在用户点击按钮后,进程对话框将显示“Please wait ...”5秒钟,然后显示结果。 我怎么做 ?请帮忙!
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();
}
}
答案 0 :(得分:1)
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();
}
}
答案 1 :(得分:0)
@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();
}
答案 2 :(得分:0)
您可以使用Jquery加载器来实现此目的。找到Jquery加载器JS和Jquery CSS并将它们包含在您的应用程序中。
在页面加载
上编写此代码$.loader({
className:"blue-with-image-2",
content:''
});
write this after the query or process is completed:
$.loader('close');
这会在完成此过程后关闭加载程序。您也可以放置一些文本而不是加载器。希望这有帮助