The method startSupportActionMode(ActionMode.Callback) is undefined for the type FragmentActivity?

Amay Diam picture Amay Diam · Jul 24, 2014 · Viewed 10.1k times · Source

I'm want to implement Action Mode Compact in Fragment Android. But I get error The method startSupportActionMode(ActionMode.Callback) is undefined for the type FragmentActivity in my code :

list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                    getActivity().startSupportActionMode(modeCallBack);

                    return true;
                }
        });

get error at getActivity().startSupportActionMode(modeCallBack);how to fix it ?

Answer

kalyan pvs picture kalyan pvs · Jul 24, 2014

From this ActionBarActivity startSupportActionMode (ActionMode.Callback callback) is method of ActionBarActivity which is used for ActionBar

if your Activity extend ActionBarActivity you can set like .

For ActionBarActivity

ActionBarActivity activity=(ActionBarActivity)getActiivty();
activity.startSupportActionMode(modeCallBack);

For Activity

getActivity().startActionMode(modeCallBack);