Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:23:51+00:00 2026-06-02T06:23:51+00:00

I have a ListView that normally is the singleChoice choiceMode . When the user

  • 0

I have a ListView that normally is the singleChoice choiceMode. When the user long presses on an item, I want to enter an action mode that allows selecting multiple items so they can perform an action on any selected items.

I am able to configure the ListView so that it is in singleChoice mode and the user is able to select list items to display a details fragment next to it and have the list item itself shown in its activated state.

I am also able to configure the ListView so that it is in the multipleChoiceModal choiceMode and performing a long press on an item starts the action mode and allows multiple selections, but now the ListView will not allow a single selection in the normal mode (no action mode).

How can I have a ListView that is in singleChoice mode and then transition it to multipleChoiceModal mode when an item is long pressed?

This is the closest I’ve been able to come up with:

  1. set the ListView to singleChoice mode
  2. set the ListView’s OnItemLongClickListener and in that listener:
    1. set the ListView’s OnItemLongClickListener to null
    2. set the ListView’s choiceMode to multipleChoiceModal
    3. call view.performClick() on the item that was long pressed.

This approach has a couple problems.

  1. The action mode isn’t started until the second time I long press on an item.
  2. When I call getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); in onDestroyActionMode I get a java.lang.StackOverflowError because that method ends up trying to destroy the action mode as well (but we have no yet returned from the destroy).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:23:53+00:00Added an answer on June 2, 2026 at 6:23 am

    I used this in one of my programs

    us the ListView.CHOICE_MODE_MULTIPLE_MODAL then lv.setMultiChoiceModeListener(new ModeCallBack());

        public class ModeCallBack implements ListView.MultiChoiceModeListener{
    
        View mSelectView;
        TextView mSelectedCount;
        ArrayList<Long> mCheckedItems;
    
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
            SharedPreferences.Editor edit = pref.edit();
    
            if(item.getItemId() == R.id.bowler_delete){
    
                for(int i=0; i<mCheckedItems.size(); i++){
                    long id = mCheckedItems.get(i);
    
                    getActivity().getContentResolver().delete(BowlersDB.CONTENT_URI,BowlersDB.ID+"="+id,null);
                }
            }else if(item.getItemId() == R.id.bowler_add_ball){
                if(mCheckedItems.size() > 1){
                    Toast.makeText(getActivity(),"Can only add bowling balls to one bowler at a time",Toast.LENGTH_SHORT).show();
                }else{
                    edit.putLong(Preferences.BOWLER_SELECTED_FOR_BALL,mCheckedItems.get(0)).commit();
    
                    ListFragment lf = new ManufacturersList();
                    FragmentTransaction ft;
                    ft = getFragmentManager().beginTransaction();
                    ft.replace(R.id.frameOne, lf).addToBackStack(null).commit();
                    //mRemover.rFragment();
                }
            }else if(item.getItemId() == R.id.add_bowler_to_team){
                for(int i=0; i<mCheckedItems.size(); i++){
    
                    long id = mCheckedItems.get(i);
                    ContentValues values = new ContentValues();
                    values.put(TeamBowlers.BOWLER_ID,id);
                    values.put(TeamBowlers.TEAM_ID,pref.getLong(Preferences.TEAM_SELECTED,1));
                    getActivity().getContentResolver().insert(TeamBowlers.CONTENT_URI, values);
    
                }
                FragmentManager fm = getFragmentManager();
                fm.popBackStack();
            }
            mode.finish();
            return true;
        }
    
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflate = getActivity().getMenuInflater();
            if(fromTeam){
                inflate.inflate(R.menu.bowlers_team_action_menu, menu);
            }else{
                inflate.inflate(R.menu.bowler_action_menu, menu);
            }
            if(mSelectView == null){
                mSelectView = (ViewGroup)LayoutInflater.from(getActivity()).inflate(R.layout.select_count_layout,null);
    
                mSelectedCount = (TextView)mSelectView.findViewById(R.id.count_tv);
    
            }
            if(mCheckedItems == null){
                mCheckedItems = new ArrayList<Long>();
            }
            mode.setCustomView(mSelectView);
            return true;
        }
    
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            mCheckedItems = null;
    
        }
    
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            if(mSelectView == null){
                mSelectView = (ViewGroup)LayoutInflater.from(getActivity()).inflate(R.layout.select_count_layout,null);
    
                mSelectedCount = (TextView)mSelectView.findViewById(R.id.count_tv);
            }
    
            if(mCheckedItems == null){
                mCheckedItems = new ArrayList<Long>();
            }
            return true;
        }
    
        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position,long id, boolean checked) {         
    
            final int count = lv.getCheckedItemCount();
            mSelectedCount.setText(String.valueOf(count));
            if(checked){
                mCheckedItems.add(id);
            }else{
                mCheckedItems.remove(id);
            }
        }
    
    }
    

    this allows for single choice single listview click and long click multiple selection. This was all pulled from the ICS messaging app so you can browse that too

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that contains button on each item. I want that the
A have a ListView that is rendered with multiple items. Now I want to
I have a ListView that is populated using an XML file. However, I want
I have a ListView that gets updated frequently, at irregular intervals. I want it
enter code here I have a ListView that have a different Layout XML for
I have a listview that I want to change the font size of. Of
I have a ListView that has a Button in the item template. Is there
I have a ListView that contains 3 checkboxes per row. I want to set
I have a listview that displays a list of profiles added by a user.
I have a listview that displays files from a directory. The user can drag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.