【发布时间】:2012-11-07 15:03:42
【问题描述】:
当我按下取消按钮时,会出现取消的 Toast 和驳回的 Toast。我该如何解决这个问题?谢谢。
编辑:按下取消按钮时我需要一个 Toast,当 ProgressDialog 正确完成时(当我关闭它时)我需要另一个不同的 Toast。但是现在,当 ProgressDialog 正确完成时,我有正确的 Toast,但是当我按下取消按钮时,结果都是 Toast。 (这是一个 ProgressDialog,带有一个以 5 递增的条形来完成)。对不起我的英语:S
myPd_bar.setOnCancelListener(new OnCancelListener(){
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,"Cancelled.",
Toast.LENGTH_LONG).show();
}});
myPd_bar.setOnDismissListener(new OnDismissListener() {
public void onDismiss(DialogInterface arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Done.",
Toast.LENGTH_SHORT).show();
}
});
myPd_bar.setButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
myPd_bar.cancel();
}
});
myPd_bar.show();
EDIT2:最终解决方案:
private int sw = 0;
myPd_bar.setOnDismissListener(new OnDismissListener() {
public void onDismiss(DialogInterface arg0) {
if (sw==0){
Toast.makeText(getApplicationContext(), "Envio Realizado Correctamente.",
Toast.LENGTH_SHORT).show();
}
myPd_bar.dismiss();
sw=0;
}
});
//Botón Cancelar.
myPd_bar.setButton("Cancelar", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
sw = 1;
//Mostramos el mensaje al cancelar.
Toast.makeText(MainActivity.this,"Envío Cancelado.", Toast.LENGTH_LONG).show();
myPd_bar.cancel();
}
});
myPd_bar.show();
【问题讨论】:
-
你真的需要这个功能吗?
标签: android progressdialog toast dismiss