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

  • Home
  • SEARCH
  • 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 8091191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:59:18+00:00 2026-06-05T19:59:18+00:00

I have a ListView with multiple checkboxes (one for each list item). What would

  • 0

I have a ListView with multiple checkboxes (one for each list item). What would be the best way to create an array containing information from the selected checkboxes.

For Example, here’s a list.

  Item 1 "Ham" Checked
  Item 2 "Turkey" NotChecked
  Item 3 "Bread" Checked  

I would like to create an array containing “ham” and “turkey”

  • 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-05T19:59:19+00:00Added an answer on June 5, 2026 at 7:59 pm

    If you used ListView’s built-in checkbox method with setChoiceMode() then you only need to call getCheckedItemIds() or getCheckedItemPositions().

    public class Example extends Activity implements OnClickListener {
        ListView mListView;
        String[] array = new String[] {"Ham", "Turkey", "Bread"};
    
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, array);
    
            mListView = (ListView) findViewById(R.id.list);
            mListView.setAdapter(adapter);
            mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    
            Button button = (Button) findViewById(R.id.button);
            button.setOnClickListener(this);
        }
    
        public void onClick(View view) {
            SparseBooleanArray positions = mListView.getCheckedItemPositions();
            int size = positions.size();
            for(int index = 0; index < size; index++) {
                Log.v("Example", "Checked: " + array[positions.keyAt(index)]);
            }
        }
    }
    

    If the Adapter is bound to a Cursor, then this becomes much more practical.

    • 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 needs to be multiple choice (i.e each list item
I have a ListView with each item being a custom layout with multiple Views
In one of my Activities, I have multiple ListView controls. Say List 1 ,
I have a listview that has multiple entries and each entry has 2 subitems.
I have a listview with multiple columns. One of the columns is a checkbox,
I have a list view full of items that contain multiple widgets each such
I have a ListView, and I want to customize the layout of each item
I have a ListView in which each item has a complex layout that contains,
In my example activity, I have - a ListView containing - multiple HorizontalScrollView containing
I am trying to create a Listview with multiple strings. Right now I have

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.