I am getting an error
The method
show(FragmentManager, String)
in the typeDialogFragment
is not applicable for the argumen
The problem is because you need to be using the support package's FragmentManager but you are using the native FragmentManager when you call getFragmentManager(). Try calling getSupportFragmentManager() when initializing your variable fm
you also have to make sure that you include DialogFragment from the Support package and not from the native package.
You can do that by importing,
import android.support.v4.app.DialogFragment;
You should use android.support.v4.app.FragmentManager
instead of android.app.FragmentManager
.
Then you should call getSupportFragmentManager()
but not getFragmentManager()
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnselectDate:
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(this.getFragmentManager(), "datePicker");
break;
default:
break;
}
}
I got this when opening a DialogFragment
even though I was not using android.support.v4.app.DialogFragment
. I had to call getActivity().getFragmentManager()
, because getSupportFragmentManager()
didn't work.
Even i had the same problem when running the code in gingerbread. But works fine for ICS. The solution is,
instead of this:
public class MainActivity extends Activity {
}
use extends FragmentActivty
public class MainActivity extends FragmentActivity {
}
As you're using android.support.v4.app.DialogFragment
, you should pass to show()
an instance of android.support.v4.app.FragmentManager
which can be queried using an getSupportFragmentManager()
call. Hope this helps.