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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:10:26+00:00 2026-05-25T13:10:26+00:00

I have a ListView that uses a custom layout that has 5 child View

  • 0

I have a ListView that uses a custom layout that has 5 child View objects (4 TextView and 1 CheckBox) in the custom layout. Only the TextViews are bound, however – the CheckBox has no corresponding field in the database. The purpose of the CheckBox is simply to identify which of the items being displayed I would like to process in “the next step”. I’m using a custom ViewBinder to assign the text values correctly (because some of the values from the DB are dates, etc).

Part of the user interface is three buttons – ‘All’, ‘None’, and ‘Invert’ that I use to toggle the status of each item in the list. For the ‘All’ button, for example, I do this with the following code (which I now know is NOT correct – I include it to show what I’m trying to do):

ListAdapter la = getListAdapter();
ListView lv = getListView();
int iCount = la.getCount();
for(int i=0; i<iCount; i++)
{
    View vv = lv.getChildAt(i);
    CheckBox cb = (CheckBox) vv.findViewById(R.id.ledgerItemCheckBox);
    cb.setChecked(true);
}

This works fine as long as the number of items in the list doesn’t exceed the list size so that all items are always visible. When I exceed that number, though, the ‘getChildAt’ function sometimes returns null because (if I understand correctly) it isn’t meant to return all of the items in the list, only those items that are visible, which results in a NullPointerException.

How can I properly set the CheckBox on all views, even if they aren’t visible?

  • 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-25T13:10:27+00:00Added an answer on May 25, 2026 at 1:10 pm

    Create a pseudo binding to one of your TextView data, create an ArrayList of Boolean objects as your back end for the checkboxes. Please note an ArrayList may not be the best data structure for your application. Fill the ArrayList with booleans set to the initial value of the corresponding position of your Cursor’s data set. When you’re binding use the ArrayList as the back end data. When you select all, none, or invert, update the Boolean objects in the ArrayList then call notifyDataSetChanged() on your SimpleCursorAdapter.

    Addition ah, the other half of the problem, yes, use the onClickListener for the CheckBoxes but use the same listener, don’t create a new object for each. Use the getPositionForView() method to get your position and update the underlying data.

    • 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 uses SimpleAdapter, each row has 2 TextViews, and I
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have a ListView that uses a custom adapter. The custom adapter's getView uses
I have a custom control that is derived from ListView . This list view
I have a custom dialog that uses an xml file to setup the layout,
I have used a list view that uses a grid view in WPF. I
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have a WPF ListView that is bound to a BindingList<T>. The binding works
I have an ownerdrawn ListView that smears when I scroll. It only affects the
I have a ListView that uses a customized adapter, but I can't click on

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.