I have a fragment in which I need to show a custom dialog.
Please check out my code below.
public class MyFragment extends Fragment{
  @Override
  public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
  }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.send_layout, container, false);
    TextView txtView = (TextView) rootView.findViewById(R.id.tv);
    txtView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openDialog();
        }
    });
   return rootView;
  }
  public void openDialog(){
      AppCompatDialog dialog = new AppCompatDialog(getContext(), R.style.package_types__dialog);
      dialog.setContentView(R.layout.package_types_dialog);
      dialog.show();
  }
}
When removing the line:
dialog.setContentView(R.layout.package_types_dialog);
there is no error, but if I use the same the following error is throwing:
FATAL EXCEPTION: main
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: Process: in.edelworks.pickedup, PID: 23866
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime: android.util.AndroidRuntimeException: Window feature must be requested before adding content
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.throwFeatureRequestIfSubDecorInstalled(AppCompatDelegateImplV7.java:1584)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.requestWindowFeature(AppCompatDelegateImplV7.java:509)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:117)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.support.v7.app.AppCompatDialog.onCreate(AppCompatDialog.java:60)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.app.Dialog.dispatchOnCreate(Dialog.java:361)
10-20 19:42:57.489 23866-23866/in.edelworks.pickedup E/AndroidRuntime:     at android.app.Dialog.show(Dialog.java:262)