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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:29:43+00:00 2026-05-25T15:29:43+00:00

I flagged the other thread to be deleted, because the main question was edited

  • 0

I flagged the other thread to be deleted, because the main question was edited so many times, that it become confusing.

So the problem is: I want to populate a ListView with checkboxes, and as I want to customize my ListView I’m not using simple_multiple_choice_mode, I’m putting my layout on list_item.xml: (for each row)

      <CheckBox>
              xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="8mm"
              android:layout_width="fill_parent"
                    android:layout_height="wrap_removed"    android:id="@+id/nomeAPP" style="?listItem"&gt;
                    </<CheckBox>

My ListView is on lista.xml

    <ListView android:id="@android:id/list" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    style="?whiteBackground">

my adapter:

      list=getListView();
                 this.setListAdapter(new ArrayAdapter&lt;String&gt;(this,
                        R.layout.list_item, aux))

So I’m trying to make a setOnCheckedChangeListener for the checkboxes, so I can store the chosed items in an array.

So I did this listener :

     CheckBox cb = (CheckBox) findViewById(R.id.CheckBox01);
                cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                         // TODO Auto-generated method stub
                         if (buttonView.isChecked()) {
                             Toast.makeText(getBaseContext(), &quot;Checked&quot;,
                                    Toast.LENGTH_SHORT).show();
                          }
                         else
                        {
                             Toast.makeText(getBaseContext(), &quot;UnChecked&quot;,
                                    Toast.LENGTH_SHORT).show();
                         }

                    }
                  });

Problem is: I get the NULL exception. The CURIOUS thing is: if I “switch” my layout for a simple

    <ScrollView android:id="@+id/widget54" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"     xmlns:android="http://schemas.android.com/apk/res/android"> 

     <LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
   <CheckBox android:text="Checkbox" android:id="@+id/CheckBox01" 
       android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> 
    </LinearLayout> 

</ScrollView> 

And forget my ListView (and my adapter), it works! So, what’s wrong with my layout?

I created a new little project just to let you guys see exactly the situation. It’s available HERE Right now does not work, but if you uncomment the adapter, change ListActivity to Activity and change setContentView, it will work (checked/unchecked toast text).

Another curious thing I found is that with ListActivity does not work never…. wondering if it’s related…

  • 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-25T15:29:43+00:00Added an answer on May 25, 2026 at 3:29 pm

    ok, i think i got your problem,

    CheckBox cb = (CheckBox) findViewById(R.id.CheckBox01);
    

    This works in the second layout, because you might have already set the view for the activity using setcontentview().

    So , the problem in your list activity is that , the above mentioned line doesn’t know , which layout it has to look for to find id,

    R.id.CheckBox01
    

    you have to get access to the layout view which you are inflating the listview , lets call it a inflatedView, and then you access the check box like this.

    CheckBox cb = (CheckBox) inflatedView.findViewById(R.id.CheckBox01);
    

    if you don’t set the content view, you have to tell the function findViewById(), where it has to look for the view.
    I would confirm this, if you post the NPE log.

    HTH.

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

Sidebar

Related Questions

I understand this question may be quickly flagged as a duplicate of many other
I have a grid containing rows flagged with different priorities. I want to color
In the Python documentation it says: A thread can be flagged as a daemon
In SEO there are a few techniques that have been flagged that need to
I have about 30 different flagged enums that I would like to put into
I've got a two vectors in class A that contain other class objects B
I have an assembly that I've built on Windows I want to run the
We have xml documents that contain lots of flagged nodes like isProduct, isActive ,
Sorry for this long question, it is flagged wiki since I'm asking for something
I want to create a method that will accept a UIButton, UIImageView, or any

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.