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 8510953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:51:06+00:00 2026-06-11T03:51:06+00:00

I have been unable to find a tutorial helping with multi-selects using cursors. As

  • 0

I have been unable to find a tutorial helping with multi-selects using cursors. As of right now my logic is working the way I want but the check boxes will not update properly. What am I overlooking?

return new AlertDialog.Builder(this).setTitle("Items")
            .setMultiChoiceItems(cur, CHECK, EDATE, new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int position, boolean checked)
                {
                    DBM.open();
                    AlertDialog AD = (AlertDialog) dialog;
                    ListView list = AD.getListView();
                    list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

                    itemCur = (Cursor) list.getItemAtPosition(position);

                    if (checked)
                    {
                        //update query
                        DBM.setChecked(checkCur.getInt(checkCur.getColumnIndex(ID)), itemId, userId, 1);
                        list.setItemChecked(1, true);
                    } else
                    {
                        DBM.setChecked(checkCur.getInt(checkCur.getColumnIndex(ID)), itemId, userId, 0);
                        list.setItemChecked(1, false);
                    }
                    DBM.close();
                }
            }).setPositiveButton("OK", new DialogButtonClickHandler()).create();
  • 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-11T03:51:07+00:00Added an answer on June 11, 2026 at 3:51 am

    So after digging into the issue a bit and going through a couple different iterations I finally found a solution that I am fairly happy with. With school and work pushing hard I have had little time outside to work on extra projects and I have been sitting with this solution for while now but unable to get it posted.

    The final piece to my puzzle was finding the changeCursor function, this fixed the issue of the old data that no longer matched the DB to load. My current hurdle is the time it takes to check a box, there is an obvious lag from clicked to updated. I have found that mutliple records update when one is clicked. I have not been able to find a valid reason for these extra updates.

    Below is the code I currently have implemented to have the multi-select working. This just the dialog code, for a working demo I will be posting a project on GitHub for a working prototype of it all in action. (Now made public, Multiselect Dialog)

    I am a fairly new Android developer, majority of my Android knowledge has been self taught and learned through the knowledge of online resources. I was working on a school project and wanted to implement a multiselect in a dialog that would update the main activity with the selected choices. Please lend any advice you can on how to improve this.

    Pros:
    – Populates check boxes properly on load.
    – Updates database when check is clicked.
    – Keeps display updated after data change.

    Cons:
    – Must click check box to update value.
    – Unable to undo changes made while in dialog. The values save onClick, I have not been able to think of a way to temporarily store the new values until confirmed by the user.
    – A single click updates multiple records, also sometimes when choices scroll off the screen values update

    @Override
    protected Dialog onCreateDialog(int id)
    {
        switch (id) {
    
        case 0:
            LayoutInflater factory = LayoutInflater.from(this);
    
            // Setup of the view for the dialog
            final View bindListDialog = factory.inflate(R.layout.multi_list_layout, null);
            multiListView = (ListView) bindListDialog.findViewById(R.id.multiList);
    
            // Because I do not know how to properly handle an undo in this situation
            // I make the dialog only close if the button is pressed and confirms the changes
            return new AlertDialog.Builder(MultiSelectDemoActivity.this).setTitle(R.string.multiSelectTitle)
                    .setCancelable(false).setView(bindListDialog)
                    .setPositiveButton(R.string.btnClose, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton)
                        {
                            updateItemList(); // In my implementation there is a list view
                                              // that shows what has been selected.
                        }
                    }).create();
        default:
            return null;
        }
    }
    
    private static final boolean ONCREATE = true;
    private static final boolean ONUPDATE = false;
    
    private void setupMultiList(Boolean newList)
    {
        demoDBM.open();
        multiCur = demoDBM.getList(userId); // Gets all items tied to the user.
        startManagingCursor(multiCur);
        // Uses the cursor to populate a List item with an invisible ID column,
        // a name column, and the checkbox
        demoDBM.close();
    
        if (newList)
        {
            // Creates a new adapter to populate the list view on the dialog
            multiAdapter = new SimpleCursorAdapter(this, R.layout.check_list_item, multiCur, new String[] { DemoDBM.ID,
                    DemoDBM.NAME, DemoDBM.SEL }, new int[] { R.id.itemId, R.id.itemName, R.id.itemCheck });
            multiAdapter.setViewBinder(new MyViewBinder());
            multiListView.setAdapter(multiAdapter);
        } else
        {
            // updates the previously made adapter with the new cursor, without changing position
            multiAdapter.changeCursor(multiCur);
        }
    }
    
    @Override
    protected void onPrepareDialog(final int id, final Dialog dialog, Bundle args)
    {
        setupMultiList(ONCREATE);
    }
    
    public class MyViewBinder implements ViewBinder
    {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex)
        {
            int checkId = cursor.getColumnIndex(DemoDBM.SEL);
    
            if (columnIndex == checkId)
            {
                CheckBox cb = (CheckBox) view;
                // Sets checkbox to the value in the cursor
                boolean bChecked = (cursor.getInt(checkId) != 0);
                cb.setChecked(bChecked); // Switches the visual checkbox.
    
                cb.setOnCheckedChangeListener(new MyOnCheckedChangeListener());
                return true;
            }
            return false;
        }
    }
    
    public class MyOnCheckedChangeListener implements OnCheckedChangeListener
    {
        @Override
        public void onCheckedChanged(CompoundButton checkBox, boolean newVal)
        {
            View item = (View) checkBox.getParent(); // Gets the plain_list_item(Parent) of the Check Box
    
            // Gets the DB _id value of the row clicked and updates the Database appropriately.
            int itemId = Integer.valueOf(((TextView) item.findViewById(R.id.itemId)).getText().toString());
            demoDBM.open();
            demoDBM.setChecked(itemId, userId, newVal);
            demoDBM.close();
    
            setupMultiList(ONUPDATE);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been unable to find a way to anti-alias my rendering on iPhone
I have been unable to find anything using the google ... If I write
I've been searching for a few hours now and have been unable to find
I have been unable to find any documentation on the .build method in Rails
I have been unable to find any decent documentation on this function. The code
I have been unable to find any documentation on properly closing database connections in
I have been researching intently and have been unable to find a solution to
After an extensive search I have been unable to find any information on this
So, similar questions have been asked before, but I have been unable to find
This is probably a simple question, but i have been unable to find a

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.