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

3

7

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 ?

Recriminate answered 24/7, 2014 at 6:29 Comment(0)
H
20

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);
Hann answered 24/7, 2014 at 6:37 Comment(8)
my activity extends Fragment sir ,,,Recriminate
For now change this line.thats enough for your requirementHann
i get this eror 'The method startActionMode(ActionMode.Callback) in the type Activity is not applicable for the arguments (ActionMode.Callback)' .. i has read the startSupportActionMode to compatible for android 2.3 and i want thisRecriminate
the parent Activity is MainActivity extends ActionBarActivityRecriminate
@user3216348 thats what i want..ok..change like my edited answerHann
thanks sir, line of that code not alerted again. but when i run code and click long item listview , i get error on log cat. i must created other post again ..Recriminate
@user3216348 ok..may be some other issue with listview..post it as other question along with logcat..Hann
In fragment mActionMode=activity.startSupportActionMode(modeCallBack); You are life saver ;)Thoraco
U
4

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;
            }
    });
Unity answered 12/8, 2017 at 10:48 Comment(0)
P
0

add call to setHasOptionsMenu(true); in

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

}
Paintbox answered 11/5, 2017 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.