MultiChoiceAdapter icon indicating copy to clipboard operation
MultiChoiceAdapter copied to clipboard

IllegalStateException: List view must belong to a SherlockActivity

Open ogero opened this issue 12 years ago • 2 comments

When AdapterView belongs to SherlockFragmentActivity instead of SherlockActivity, an exception is thrown.

MultiChoiceAdapterHelper from package "com.manuelpeinado.multichoiceadapter.extras.actionbarsherlock" only checks if adapterview context is an instance of SherlockActivity.

**For a quick fix, change startActionMode method to:

    @Override
    protected void startActionMode() {
        if (!(adapterView.getContext() instanceof SherlockActivity)
                && !(adapterView.getContext() instanceof SherlockFragmentActivity)) {
            throw new IllegalStateException("List view must belong to a SherlockActivity or a SherlockFragmentActivity");
        }
        if (!(owner instanceof ActionMode.Callback)) {
            throw new IllegalStateException("Owner adapter must implement ActionMode.Callback");
        }
        if (adapterView.getContext() instanceof SherlockActivity) {
        }
        if ((adapterView.getContext() instanceof SherlockActivity)) {
            SherlockActivity activity = (SherlockActivity) adapterView.getContext();
            actionMode = activity.startActionMode((ActionMode.Callback) owner);
        } else {
            SherlockFragmentActivity activity = (SherlockFragmentActivity) adapterView.getContext();
            actionMode = activity.startActionMode((ActionMode.Callback) owner);
        }
    }

ogero avatar Nov 24 '13 01:11 ogero

+1

ruimateus avatar Dec 06 '13 17:12 ruimateus

Thanks a lot for the report, I'll fix this over the next few days and release a new version of the lib.

ManuelPeinado avatar Dec 23 '13 18:12 ManuelPeinado