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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:56:26+00:00 2026-05-20T12:56:26+00:00

I’ve been working on this application but have come across a problem that I

  • 0

I’ve been working on this application but have come across a problem that I have been unable to figure out. I have a listview that is populated with the contents from an adapter, and each row has their specific information (Uniform). The problem comes when I try to retrieve the value of a checkbox that is found in that particular row.

The code in question is below:

I build an AlertDialog object so I can get my information from the user. My layout code consists of a LinearLayout in horizontal orientation with 3 elements an image, text, check box. I build my AlertDialog with R.layout.listview_layout, which is a custom layout that I made.

One thing I tried to do is get the CheckBox View from the adapter, however; when I look at it via cb.isChecked(), no matter what row i’m on its always unchecked (aka false). In order to debug this further I took the same adapter and retrieved the text via the same methodology and it returned specific information about that row, as it should.

Any ideas how I can handle this?

Simply Put:

I would just like to get the value of the CheckBox at each given row


c = help.returnContacts();

    AlertDialog.Builder ab = new AlertDialog.Builder(this);
    ab.setTitle("Select contacts");

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(
            getApplicationContext(), R.layout.listview_layout, c,
            new String[] { ClientOpenDbHelperUtility.COL_NAME,
                    ClientOpenDbHelperUtility.COL_SEL }, new int[] {
                    R.id.txt_name, R.id.cb_select });
    ab.setAdapter(adapter, null);

    ab.setPositiveButton("Confirm", new Dialog.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            Cursor c = adapter.getCursor();
            for (int i = 0; i < adapter.getCount(); i++) {

                CheckBox cb = (CheckBox) adapter.getView(i, null, null)
                        .findViewById(R.id.cb_select);
                TextView t = (TextView) adapter.getView(i, null, null)
                        .findViewById(R.id.txt_name);

                Log.d("DEBUG", "Checked = " + cb.isChecked());
                Log.d("DEBUG", "Message = " + t.getText().toString());
                if (cb.isChecked()) {

                    help
                            .updateSelection(
                                    c
                                            .getColumnIndex(ClientOpenDbHelperUtility.COL_UID),
                                    true);
                } else {
                    help
                            .updateSelection(
                                    c
                                            .getColumnIndex(ClientOpenDbHelperUtility.COL_UID),
                                    false);
                }

            }
            c.close();
            help.closeAll();

        }

    });
    ab.show();

}

Thanks for reading!

  • 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-05-20T12:56:26+00:00Added an answer on May 20, 2026 at 12:56 pm

    You shouldn’t call getView directly. Doing so generates a fresh view (or recycles and overwrites an old one) based on the contents of your database.

    Also, once your rows scroll off the top or bottom of the screen they will be recycled for use in new rows that appear. All of your data but the currently visible rows are most likely to have already vanished by the time your onClick method gets called.

    You have two options:

    1. Persist changes immediately to the database – set an OnClickListener on your checkbox or on the row and update your database on each click event.

    2. Save changes to an instance variable and then apply later – define a Map<Integer, Boolean> changes instance variable for your activity and call changes.put(position, isChecked) whenever there is a click. Then when your user clicks “Apply” or whatever your onClick is, go through changes and persist each one to the database. It’s basically the same as what you have now except you would be using a stable object to store the unsaved changes.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.