我定義爲這個自定義對話框沒有取消,甚至設置撤銷真正
public class ActivityIndicator extends Dialog
{
private ImageView progress;
private ImageView bottomProgress;
private int type = INDICATOR_SIMPLE;
public static final int INDICATOR_SIMPLE = 0;
public static final int INDICATOR_BOTTOM = 1;
public ActivityIndicator(Context context, int theme, int type)
{
super(context, theme);
this.type = type;
onCreate(null);
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_indicator);
progress = (ImageView) findViewById(R.id.progress);
bottomProgress = (ImageView) findViewById(R.id.bottomProgress);
if(type == INDICATOR_BOTTOM)
{
progress.setVisibility(View.INVISIBLE);
}
else if(type == INDICATOR_SIMPLE)
{
bottomProgress.setVisibility(View.INVISIBLE);
}
this.setCancelable(false);
}
@Override
public void show()
{
progress.clearAnimation();
bottomProgress.clearAnimation();
if(type == INDICATOR_BOTTOM)
{
progress.setVisibility(View.INVISIBLE);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.rotating_img);
bottomProgress.startAnimation(anim);
}
},400);
}
if(type == INDICATOR_SIMPLE)
{
bottomProgress.setVisibility(View.INVISIBLE);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.rotating_img);
progress.startAnimation(anim);
}
},400);
}
super.show();
}
@Override
public void dismiss()
{
super.dismiss();
progress.clearAnimation();
bottomProgress.clearAnimation();
}
}
在我的活動我初始化爲自定義ActivityIndicator後:
indicator = new ActivityIndicator(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen, ActivityIndicator.INDICATOR_SIMPLE);
現在在代碼所示,默認樣式可取消是錯誤的。
然而,在某些時候,我也希望把它取消,這裏是我的代碼:
indicator.setCancelable(true);
indicator.setOnCancelListener(new DialogInterface.OnCancelListener()
{
@Override
public void onCancel(DialogInterface dialog)
{
finish();
}
});
indicator.show();
當我嘗試按後退按鈕,沒有任何反應,該dialog
不取消,也不是取消收聽。這裏有什麼問題?爲什麼它不能自動取消後退鍵的按下
而不是'finish()'嘗試'dismiss()'或'dialog.dismiss()' – Pankaj
@Clairvoyant這就是要點..在哪裏調用這些:)取消偵聽器不工作。後退按下只是沒有做任何事情 –
對不起,我沒有看到你的整個問題 – Pankaj