我有许多不同的状态,我需要根据这些状态以AlertDialog
. 为每个警报创建一个单独的类简直太疯狂了。我现在拥有的是:
class FeedbackAlertDialog extends DialogFragment {
private String message;
private int action;
FeedbackAlertDialog() {
}
FeedbackAlertDialog(String message, int action) {
this.message = message;
this.action = action;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setCancelable(false)
.setTitle(message)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
switch (action) {
case action: // It's impossible because the int should be final
}
startActivity(new Intent(getActivity(), MainActivity.class));
}
}).show();
}
}
问题是我不能使用switch
,因为int
应该是最终的。怎么想出这种情况?