构造函数(注意 ListPickerHandler)
public StarredListPickerDialogFragment(ListPickerHandler h) {
handler = h;
mSelectedItems = new ArrayList<StarredList>();
}
这就是我调用父片段方法的方式(定义实现 ListPickerHandler 接口)
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button negative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.setEnabled(false);
negative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
handler.onNegativeButtonAction(mSelectedItems);
}
});
positive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
handler.onPositiveButtonAction(mSelectedItems);
}
});
}
});
现在,当 android os 调用 onSaveInstanceState() 时,麻烦就来了。处理程序不再定义,我实际上没有线索来处理这种情况..