Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with DialogFragment in Android

On click i want display a dialog but i get an error in the show word. This part of code is in my MainActivity that extends and Activity.. Instead, the dialog i want display, is created in another class that extends DialogFragment.

Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
                             DialogFragment df=new DialogTrial();
                             df.show(this.getFragmentManager(), "MyDialog"); 

The error:

The method show(android.support.v4.app.FragmentManager, java.lang.String) in the type DialogFragment is not applicable for the arguments (android.app.FragmentManager, java.lang.String)

I tried everything: this.getFragmentManager(), getActivity(), context, thisbut always same error.

like image 365
Atlas91 Avatar asked Mar 15 '14 12:03

Atlas91


2 Answers

You are passing wrong Fragment manager.. Change this line

 df.show(this.getFragmentManager(), "MyDialog");

into

df.show(this.getSupportFragmentManager(), "MyDialog");
like image 184
kalyan pvs Avatar answered Sep 27 '22 21:09

kalyan pvs


If you are using the support package, please check your imports:

I think you are mixing classes from support package and not.

If you use support package:

  1. make your activity extends FragmentActivity.
  2. Use getSupportFragmentManager()
  3. check all imports for example: import android.support.v4.app.DialogFragment;
like image 21
Luca Sepe Avatar answered Sep 27 '22 20:09

Luca Sepe