Example usage for android.widget ListView setMultiChoiceModeListener

List of usage examples for android.widget ListView setMultiChoiceModeListener

Introduction

In this page you can find the example usage for android.widget ListView setMultiChoiceModeListener.

Prototype

public void setMultiChoiceModeListener(MultiChoiceModeListener listener) 

Source Link

Document

Set a MultiChoiceModeListener that will manage the lifecycle of the selection ActionMode .

Usage

From source file:com.boardgamegeek.util.actionmodecompat.ActionModeHoneycomb.java

public static void beginMultiChoiceMode(ListView listView, FragmentActivity activity,
        final MultiChoiceModeListener listener) {
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        ActionModeHoneycomb mWrappedActionMode;

        @Override//w  w  w .  j a v  a  2s  . c o  m
        public void onItemCheckedStateChanged(android.view.ActionMode actionMode, int position, long id,
                boolean checked) {
            listener.onItemCheckedStateChanged(mWrappedActionMode, position, id, checked);
        }

        @Override
        public boolean onCreateActionMode(android.view.ActionMode actionMode, Menu menu) {
            if (mWrappedActionMode == null) {
                mWrappedActionMode = new ActionModeHoneycomb();
                mWrappedActionMode.mNativeActionMode = actionMode;
            }
            return listener.onCreateActionMode(mWrappedActionMode, menu);
        }

        @Override
        public boolean onPrepareActionMode(android.view.ActionMode actionMode, Menu menu) {
            if (mWrappedActionMode == null) {
                mWrappedActionMode = new ActionModeHoneycomb();
                mWrappedActionMode.mNativeActionMode = actionMode;
            }
            return listener.onPrepareActionMode(mWrappedActionMode, menu);
        }

        @Override
        public boolean onActionItemClicked(android.view.ActionMode actionMode, MenuItem menuItem) {
            return listener.onActionItemClicked(mWrappedActionMode, menuItem);
        }

        @Override
        public void onDestroyActionMode(android.view.ActionMode actionMode) {
            listener.onDestroyActionMode(mWrappedActionMode);
        }
    });
}

From source file:com.btmura.android.reddit.app.AbstractListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, savedInstanceState);
    ListView l = (ListView) v.findViewById(android.R.id.list);
    l.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    l.setMultiChoiceModeListener(this);
    return v;//from  w w  w . j  a va2  s  .co m
}

From source file:com.nagopy.android.mypkgs.ApplicationListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ListView listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(this);

    Context context = getActivity().getApplicationContext();
    FilterType filterType = FilterType.valueOf(getArguments().getString(ARG_FILTER_TYPE));
    final ApplicationListAdapter applicationListAdapter = new ApplicationListAdapter(context, filterType);
    setListAdapter(applicationListAdapter);

    loadApplications();/*from   w  w w. ja  v a  2 s  .  c om*/
}

From source file:simonlang.coastdove.usagestatistics.ui.app_details.AppUsageDataListFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    this.loaderID = 100;

    ListView listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override//from  w ww.  j  a  v  a 2 s. c o  m
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            listAdapter().toggleSelected(position);
            mode.setTitle(listAdapter().selectedCount() + "");
            listAdapter().notifyDataSetChanged();
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.app_usage_data_context_menu, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.item_context_delete:
                List<AppUsageDataUIContainer> selectedItems = listAdapter().getSelectedItems();
                List<Integer> selectedItemsPrimaryKeys = new LinkedList<>();
                for (AppUsageDataUIContainer selectedItem : selectedItems)
                    selectedItemsPrimaryKeys.add(selectedItem.id);
                new SQLiteDataRemover(getActivity(), selectedItemsPrimaryKeys).run();
                Toast toast = Toast.makeText(getActivity(), getString(R.string.toast_data_removed),
                        Toast.LENGTH_SHORT);
                toast.show();
                mode.finish();
                getLoaderManager().restartLoader(loaderID, getArguments(), AppUsageDataListFragment.this);
                getListView().invalidate();
                return true;
            default:
                return false;
            }
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            listAdapter().resetSelected();
        }
    });
}

From source file:com.sawyer.advadapters.app.adapters.jsonadapter.JSONAdapterFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ListView lv = (ListView) inflater.inflate(R.layout.listview, container, false);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    lv.setMultiChoiceModeListener(new OnCabMultiChoiceModeListener());
    return lv;//from   ww  w  . j av  a 2 s .  com
}

From source file:com.jhk.whysoformal.activity.moveMove.fragment.MoveMoveFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = super.onCreateView(inflater, container, savedInstanceState);

    ListView listView = (ListView) view.findViewById(android.R.id.list);

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override/*from ww w . j a  v a 2  s.  c  om*/
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
        }
    });

    return view;
}

From source file:com.akalipetis.fragment.ActionModeListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ListView list = getListView();
    list.setOnItemLongClickListener(this);
    if (Build.VERSION.SDK_INT >= 11)
        list.setMultiChoiceModeListener(new InternalV11Listener());
}

From source file:org.jraf.android.bikey.app.ride.list.RideListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setEmptyText(getString(R.string.ride_list_empty));

    ListView listView = getListView();
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override/*  ww w  . j a v a 2s .com*/
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.setTitle(R.string.ride_list_title);
            int quantity = getListView().getCheckedItemCount();
            mode.setSubtitle(
                    getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity));
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.ride_list_contextual, menu);
            return true;
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            int quantity = getListView().getCheckedItemCount();
            mode.setSubtitle(
                    getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity));
            // Enable share / edit if only one item is selected (can't share / edit several items at the same time)
            mode.getMenu().findItem(R.id.action_share).setVisible(quantity == 1);
            mode.getMenu().findItem(R.id.action_edit).setVisible(quantity == 1);
            // Enable merge only if several items are selected
            mode.getMenu().findItem(R.id.action_merge).setVisible(quantity > 1);
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            long[] checkedItemIds = getListView().getCheckedItemIds();
            long checkedItemId = checkedItemIds[0];
            Uri checkedItemUri = ContentUris.withAppendedId(RideColumns.CONTENT_URI, checkedItemId);
            switch (item.getItemId()) {
            case R.id.action_delete:
                getCallbacks().showDeleteDialog(checkedItemIds);
                mode.finish();
                return true;

            case R.id.action_share:
                getCallbacks().showShareDialog(checkedItemUri);
                mode.finish();
                return true;

            case R.id.action_edit:
                getCallbacks().edit(checkedItemUri);
                mode.finish();
                return true;

            case R.id.action_merge:
                getCallbacks().showMergeDialog(checkedItemIds);
                mode.finish();
                return true;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }
    });
}

From source file:com.akalipetis.action_mode_list_fragment.ActionModeListFragment.java

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ListView list = getListView();
    list.setOnItemLongClickListener(this);

    if (Build.VERSION.SDK_INT >= 11) {
        list.setMultiChoiceModeListener(new InternalV11Listener());
    }/*from w  ww . ja  v  a  2 s .com*/
}

From source file:com.btmura.android.reddit.app.CommentListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, savedInstanceState);
    ListView lv = (ListView) v.findViewById(android.R.id.list);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    lv.setMultiChoiceModeListener(this);
    lv.setDivider(null);/*from  ww w  . ja  v a2s  .c o  m*/
    return v;
}