0

When I try to execute the DialogoFragment in a Fragment, it tells me to create the Show method and I already tried with: this, getContext (), getFragmenteManager (), getActivity (). GetFragmenteManager (). In the Activity it does not give me problems to execute it only in the Fragment.

I am running this code from a Fragment:

public void onActivityCreated(Bundle savedInstanceState) {
 btnComentario = (Button) getView().findViewById(R.id.btnComentario);
 btnComentario.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
    super.onActivityCreated(savedInstanceState);
      (new MyDialogFragment()).show(getActivity().getFragmentManager(), "DialogFrament");
      }
    });

}

Thanks for the help

user3139428
  • 83
  • 1
  • 2
  • 7

1 Answers1

0
 @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
 // TODO Auto-generated method stub
        super.onViewCreated(view, savedInstanceState);
 btnComentario = (Button) getView().findViewById(R.id.btnComentario);
 btnComentario.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
     FragmentManager fm = getFragmentManager();
            MyDialogFragment dialogFragment = new MyDialogFragment();
            dialogFragment.show(fm,"");
      }
    });
}

Try this method on onViewCreated inside fragment. It's working solution. If it works fine kindly Tick the answer so as to pass info for researchers.

abhil nair
  • 188
  • 1
  • 1
  • 15
  • Thanks but I get the same: Cannot resolve method show. – user3139428 Apr 11 '17 at 13:10
  • post your Log Here. – abhil nair Apr 11 '17 at 13:16
  • Check Your Import use `import android.support.v4.app.DialogFragment;` – abhil nair Apr 11 '17 at 13:20
  • Yes i have imported – user3139428 Apr 11 '17 at 15:52
  • Post your full code and your error Log for much clarity – abhil nair Apr 12 '17 at 04:06
  • I do not get error, just do not let me declare it. That is to say I get the arguments in red and winged the bulb telling me: Cannot resolve method show – user3139428 Apr 12 '17 at 10:03
  • Check your fragment import use - `import android.support.v4.app.Fragment;` your fragment manager import use - `import android.support.v4.app.FragmentManager;` – abhil nair Apr 12 '17 at 10:11
  • Thanks was that, I had some with app and others with support.v4. I've put them all with app, now it does not give error or failure to write it but I do not execute the DialogoFragment. It is implemented and both the DialogoFragment and the executor uses the app implementations. Do you know why it could be? – user3139428 Apr 13 '17 at 11:49
  • Could you brief your query more? If the issue with the question has finished you can mark the answer as correct by selecting tick so it can help other researchers. – abhil nair Apr 13 '17 at 12:33
  • No me da ningún fallo, pero al ejecutar el diálogo, la aplicación es closes.Everything con: android.app importación. (new AddMyDialogFragment()).show(getFragmentManager(), "MyDialogFragment"); – user3139428 Apr 14 '17 at 09:48
  • It does not give me any flaws, but when I run the dialog, the application is closes.Everything with: import android.app. Code: (new AddMyDialogFragment()).show(getFragmentManager(), "MyDialogFragment"); – user3139428 Apr 14 '17 at 11:34
  • Kindly post this as a new question with the error log for much clarity. – abhil nair Apr 17 '17 at 04:58