Custom Dialog Fragment

前端 未结 2 1769
灰色年华
灰色年华 2021-01-13 04:34

I am trying to create a simplistic dialog similar to a DatePickerDialog. The Dialog that I am creating should provide the user with an array of ima

2条回答
  •  一整个雨季
    2021-01-13 04:48

    There are different ways you can create your dialog either using OnCreateView method or using OnCreateDialog method if you are extending the DialogFragment class and so the implementation goes in a different way for both.

    You should return your Dialog instance from OnCreateDialog method.

    How to show the dialog in a Activity

     FragmentTransaction ft = getFragmentManager().beginTransaction();
     Fragment prev = getFragmentManager().findFragmentByTag("YourFragmentID");
    
     if (prev != null) {
            ft.remove(prev);
        }
     ft.addToBackStack(null);
    
     PicturePickerFragment pf = new PicturePickerFragment();
     pf.show();
    

    May be you can refer to this link which is a nice example from official AndroidDeveloper's site.

提交回复
热议问题