Search code examples
androidlistviewandroid-actionmode

Cannot start ActionMode Callback in Android for ListView ItemLongClick


I do the following inside the onCreate

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

            if (mActionMode != null) {
                return false;
            }


            mActionMode = TeamActivity.this.startActionMode(TeamActivity.this);
            view.setSelected(true);

            return true;
        }
    });

But TeamActivity.this inside startActionMode is has red line and says that android.view.ActionMode.Callback cannot be applied in Activity

why? what I am missing here?


Solution

  • If you are able to access the method startSupportActionMode then it sounds like you have imported the wrong ActionMode.Callback class.

    android.view.ActionMode - what you need to import.
    android.support.v7.view.ActionMode - what you have imported.

    Please check your imports at the top of the class.