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 ?
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);
try this
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
((AppCompatActivity) getActivity()).startSupportActionMode(mActionModeCallback);
return true;
}
});
add call to setHasOptionsMenu(true); in
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}