use*_*350 5 android progressdialog android-button android-dialog onclicklistener
我使用ProgressDialog向用户显示他必须等待并且在用户必须等待时使我的应用程序的表面"不可触及".我在progressDialog中添加了一个Button,如果某些条件为真,它应该启动一些操作.问题是,每次用户按下按钮时,progressDialog都会自动被解除.即使没有触发任何动作.如何在调用onClick时阻止progressDialog被解雇?
感谢和问候
编辑:
connectingDialog = new ProgressDialog(this);
connectingDialog.setCancelable(false);
connectingDialog.setCanceledOnTouchOutside(false);
connectingDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "start", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
/*if(isPrepared)
startGame();*/
connectingDialog.show(); // does not work, too
}
});
connectingDialog.show();
Run Code Online (Sandbox Code Playgroud)
OnClickListenerAfter the ProgressDialog.与DialogAndroid中可用的其他一些不同,ProgressDialog没有setNeutralButton()方法,因此您需要在显示onClickListener之后设置,ProgressDialog如下所示:
connectingDialog = new ProgressDialog(this);
connectingDialog.setCancelable(false);
connectingDialog.setCanceledOnTouchOutside(false);
// Create the button but set the listener to a null object.
connectingDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "start",
(DialogInterface.OnClickListener) null )
// Show the dialog so we can then get the button from the view.
connectingDialog.show();
// Get the button from the view.
Button dialogButton = connectingDialog.getButton( DialogInterface.BUTTON_NEUTRAL );
// Set the onClickListener here, in the view.
dialogButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick ( View view ) {
if (isPrepared) {
connectingDialog.dismiss();
startGame();
}
// Dialog will not get dismissed unless "isPrepared".
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1711 次 |
| 最近记录: |