I am in the process of converting my dialogs to DialogFragments
. I\'m following the instructions here but it looks like they are using it in an Activity<
Shouldn't you use getSupportFragmentManager()
and add (.add(fragment, tag)
) the new instance of your fragment to the FragmentTransaction
by doing .beginTransaction()
and then call commit()
? I guess thats what you are trying to do.
getActivity()
returns null
since your new Fragment instance is not attached to the Activity (native FragmentActivity/Activity
or SherlockFragmentActivity/SherlockActivity
, whatever it is).
Do some readings about using fragments. Instantiantion of the fragment is not enough. Find about underlying operations after instantiation.
Use :
getActivity().getApplicationContext()
Instead of:
getActivity()
EDIT:
Use this method
@Override
public void onAttach(SupportActivity activity) {
super.onAttach(activity);
}