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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:47:49+00:00 2026-05-17T20:47:49+00:00

I’ve created a custom ListView by extending SimpleCursorAdapter. The result is IMAGE + CheckedTextView

  • 0

I’ve created a custom ListView by extending SimpleCursorAdapter. The result is IMAGE + CheckedTextView (Text + Checkbox).

After I had issues with the wrong checkboxes getting checked (see here) I had to remove lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); from onCreate.

Now I click on a ListItem line and it checks the right checkbox.

What I’m trying to do is make a LinearLayout.VISIBLE when 1 or more checkboxes are checked AND make LinearLayout.GONE when no checkbox is checked.

Here is the code:

lv.setOnItemClickListener(new OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

CheckedTextView markedItem = (CheckedTextView) view.findViewById(R.id.btitle);

if (!markedItem.isChecked()) {
 markedItem.setChecked(true);

 //show bottom control panel
 findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.VISIBLE);


} else {
 markedItem.setChecked(false);

 SparseBooleanArray lala = ((ListView) parent).getCheckedItemPositions();

 //if no checkbox is checked, hide bottom control panel
 if (lala == null) {
  findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.INVISIBLE);
 }
}
view.refreshDrawableState();
//showSortBtn(markedItem);

}
});

This is how I bind the listView to the custom adapter:

projection = new String[] { Browser.BookmarkColumns._ID,
                Browser.BookmarkColumns.FAVICON, Browser.BookmarkColumns.TITLE,
                Browser.BookmarkColumns.URL };
        displayFields = new String[] { Browser.BookmarkColumns.TITLE,
                Browser.BookmarkColumns.FAVICON, Browser.BookmarkColumns.URL };
        int[] displayViews = new int[] { android.R.id.icon, android.R.id.text1 };

        cur = managedQuery(BOOKMARKS_URI, projection,
                Browser.BookmarkColumns.BOOKMARK + " == 1", null, Browser.BookmarkColumns.VISITS + " DESC");

        setListAdapter(new ImageCursorAdapter(this,
                android.R.layout.simple_list_item_single_choice, cur,
                displayFields, displayViews));

I have two issues with this:

  1. if I check 2 or more checkboxes and then uncheck only one, the LinearLayout disappears which means SparseBooleanArray lala = ((ListView) parent).getCheckedItemPositions(); is null. why is it null if there are still other checkboxes checked?

  2. if I switch findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.INVISIBLE); to findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.GONE); (like I want to do) the first checkbox is being checked correctly and after the LinearLayout is GONE, everything is a mess again, just like on my previous question.

Appreciate any help!

  • 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-17T20:47:49+00:00Added an answer on May 17, 2026 at 8:47 pm

    Why are you expecting getCheckedItemPositions() to return null if there aren’t checked items? It looks like your choice mode is wrong

    A SparseBooleanArray which will return true for each call to get(int position) where position is a position in the list, or null if the choice mode is set to CHOICE_MODE_NONE.

    The array should only be null if it’s choice_mode_none.

    Why not try something like this?

    if (((ListView) parent).getCheckedItemPositions().size() > 0){
    
        findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.VISIBLE);
    else{
    
        findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.GONE;
    }
    

    Update

    I’m pretty sure it has to do with this line

     View v = inView;
            if (v == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = inflater.inflate(R.layout.image_list, null);
            }
    

    You get the view, then reassign the view to the inflater. I’m kind of at a loss though at exactly why it would give the behavior you’re exeriencing. You might also want to try the bindView() method though I’m not sure why. Maybe instead of using the default android layout (the one you’re giving to the setAdapter, make your own layout. It clearly is getting confused as to which view is assigned to which layout.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
Basically, what I'm trying to create is a page of div tags, each has
In order to apply a triggered animation to all ToolTip s in my app,
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.