當在特定片段的設備上點擊「返回」按鈕時,我想提醒用戶並讓他們決定隱藏應用程序或保留。下面的代碼段:如何調用alertDialog中一個活動的超類方法(Android Studio)
@Override
public void onBackPressed() {
Fragment f = getSupportFragmentManager().findFragmentById(R.id.container);
if(f instanceof PlanListFragment){
builder.setPositiveButton(R.string.alert_Cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
builder.setNegativeButton(R.string.alert_OK, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// I want to call this: **super.onBackPressed()**; but super is not recognized at all here.
}
});
AlertDialog dialog = builder.create();
dialog.show();
}else{
super.onBackPressed();
}
}
如上評論,我怎麼能叫單擊「確定」按鈕,當這個「supper.onBackPressed()」方法?
在此先感謝!
肖恩
所以你想關閉對話框並關閉活動,當用戶按「確定」。 –