Reputation: 127
Trying to use startActionMode in fragment but got this error at
mMode = startActionMode(new AnActionModeOfEpicProportions()); LINE 55
How to slove this? ActionMode not supported in Fragment?
Thanks
Upvotes: 1
Views: 2785
Reputation: 124
in support library you can use it :
((ActionBarActivity) getActivity()).startSupportActionMode (new AnActionModeOfEpicProportions());
Upvotes: 0
Reputation: 30168
You are trying to invoke an instance method of an Activity from a static Fragment (i.e. one that is separate from the instance of the Activity). Remembrer that you can always access the activity that contains your fragment using getActivity()
. So:
if (getActivity() != null) {
mMode = getActivity().startActionMode(new AnActionModeOfEpicProportions());
}
A cleaner approach would be to declare an interface class to manage the communication between fragments and activities.
Upvotes: 4