gpt4 book ai didi

java - 如何添加一个旋转样式的进程对话框 5 秒

转载 作者:行者123 更新时间:2023-12-01 13:18:33 24 4
gpt4 key购买 nike

在下面的代码中,我希望在用户单击“检查根目录”后有一个旋转样式的进程对话框 5 秒钟。基本上,用户点击按钮后,进程对话框会显示“请稍候...”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();
}
}

最佳答案

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();
}

}

关于java - 如何添加一个旋转样式的进程对话框 5 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22248762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com