Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void showDialog(FragmentActivity activity, String title, String msg,
- String positiveButtonText, String negativeButtonText, int id, Bundle args) {
- if (activity.isFinishing()) {
- return;
- }
- FragmentManager fmgr = activity.getSupportFragmentManager();
- FragmentTransaction ft = fmgr.beginTransaction();
- Fragment prev = fmgr.findFragmentByTag(TAG);
- if (prev != null) {
- try {
- ft.remove(prev);
- } catch (IllegalStateException ex) {
- // issue: http://code.google.com/p/android/issues/detail?id=17029
- }
- }
- TwoButtonDialogFragment newFragment = new TwoButtonDialogFragment();
- if (args == null) {
- args = new Bundle();
- }
- args.putString("title", title);
- args.putString("message", msg);
- args.putString("positiveButtonText", positiveButtonText);
- args.putString("negativeButtonText", negativeButtonText);
- args.putInt("id", id);
- newFragment.setArguments(args);
- newFragment.setCancelable(false);
- newFragment.show(fmgr, TAG); // exception is thrown here
- ft.commit();
- }
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- final Bundle args = getArguments();
- String title = args.getString("title");
- String msg = args.getString("message");
- String positiveButtonText = args.getString("positiveButtonText");
- String negativeButtonText = args.getString("negativeButtonText");
- final int id = args.getInt("id");
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- if (!TextUtils.isEmpty(title)) {
- builder.setTitle(title);
- }
- builder.setMessage(msg);
- final TwoButtonDialogHandler handler = (TwoButtonDialogHandler) getActivity();
- builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- handler.doPositiveClick(id, args);
- }
- });
- builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- handler.doNegativeClick(id, args);
- }
- });
- return builder.create();
- }
Advertisement
Add Comment
Please, Sign In to add comment