xAnGz
xAnGz

Reputation: 127

Actionbarsherlock ActionMode in Fragment Support

Trying to use startActionMode in fragment but got this error at

mMode = startActionMode(new AnActionModeOfEpicProportions()); LINE 55

http://pastebin.com/d9jzg9UC

How to slove this? ActionMode not supported in Fragment?

Thanks

Upvotes: 1

Views: 2785

Answers (2)

Vahid.Ahani
Vahid.Ahani

Reputation: 124

in support library you can use it :

((ActionBarActivity) getActivity()).startSupportActionMode (new AnActionModeOfEpicProportions());

Upvotes: 0

dmon
dmon

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

Related Questions