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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:58:15+00:00 2026-05-24T08:58:15+00:00

Currently i have a checkbox on my listview,from the BaseAdapter i have set the

  • 0

Currently i have a checkbox on my listview,from the BaseAdapter i have set the checkbox id with my own id.
When i access this id from the Activity . I get null pointer exception? Though i debug i still have that null pointer exception?

Is it not possible to set id of the checkbox manually. Checkbox does have a method
setId(int id).

Any thoughts on null pointer exception on checkBox.getId()?
this is my getView() where i have set the checkBox id.

viewHolder.checkBox.setId(myList.get(position).getId());

On Activity i have done as this because i have to delete all the checked CheckBox.

private void deleteCheckItems() {
    SparseBooleanArray booleanArray = listView.getCheckedItemPositions();
    for (int i = 0; i < listView.getCount(); i++) {
        if (booleanArray.get(i))
            Toast.makeText(getBaseContext(), " the selected index is " + i, Toast.LENGTH_SHORT).show();
    }
}

I am getting null pointer exception from this method

Edited: My Source Code is as:

public View getView(int position, View view, ViewGroup parent){
    ViewHolder viewHolder;
    if(view==null){
        viewHolder = new ViewHolder();
        view = layoutInfalter.inflate(R.layout.item_row,null);
        viewHolder.checkBox = (CheckBox)view.findViewById(R.id.CheckBoxId);

        if(VIEW_MODE==-1){
            viewHolder.checkBox.setVisibility(View.INVISIBLE);
        }else{
             myAdapter.setViewMode(1);
             viewHolder.checkBox.setVisibility(View.VISIBLE);
                         viewHolder.checkBox.setId(myList.get(position).getId());      

        }
        viewHolder.text1= (TextView)view.findViewById(R.id.text1);
        viewHolder.text2 =TextView)view.findViewById(R.id.text2);
        view.setTag(viewHolder);

    }else{
        viewHolder = (ViewHolder)view.getTag();
    }
    viewHolder.text1.setText(myList.get(position).getText1());
    viewHolder.text2.setText(myList.get(position).getText2());
    //viewHolder.checkBox.setId(myList.get(position).getId());
    return view;
}
  • 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-24T08:58:16+00:00Added an answer on May 24, 2026 at 8:58 am

    this might help you!!

    It works for me:

    ROW.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:background="#ffffff">
    
    <RelativeLayout
    android:id="@+id/actionsLayout"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:paddingRight="10dip"
    android:gravity="center"
    android:paddingBottom="10dip">
    
     //change it to CheckBox
      <ImageView
    android:id="@+id/markFav"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/heart"/>
    
    </RelativeLayout>
    
    <RelativeLayout
    android:id="@+id/textLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:layout_toLeftOf="@+id/actionsLayout"
    android:layout_margin="10dip">
    <TextView
    android:id="@+id/status"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:lines="4"
    android:gravity="center_vertical"
    android:ellipsize="end"
    android:textColor="#000000"
    android:text="Row Text Here"/>
     </RelativeLayout>
    
      </RelativeLayout>
    

    In the above xml change ImageView to CheckBox. and edit your getView like This:

    GetView method in your baseAdapter:

        public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                System.out.println("in getView");
                 ViewHolder holder;
                 if (convertView == null) {
                 convertView = mInflater.inflate(R.layout.row, null);
                 holder = new ViewHolder();
                 System.out.println("After holder");
    
                 holder.name= (TextView) convertView.findViewById(R.id.status);
    
        //Change this to Checkbox and also add that checkbox in your ViewHolder and edit your implementation as per required.
                 holder.heart = (ImageView) convertView.findViewById(R.id.image);
                 //do not set on Click Listener if it is a CheckBox
                 holder.heart.setOnClickListener(this);
    
    
                 System.out.println("After holder text");
                 convertView.setTag(holder);
                 } else {
                 holder = (ViewHolder) convertView.getTag();
    
                 System.out.println("in else part");
                 }
                 //convertView.setBackgroundColor((position & 1) == 1 ? Color.WHITE : Color.LTGRAY);
                 System.out.println("After set background");
    
                if(status.size()>0){
                     holder.name.setText(status.get(position).desc.toString());
    
                 }
                 return convertView;
            }
    
            public void onClick(View v) {
                // TODO Auto-generated method stub
                switch(v.getId()){
                case R.id.markFav:
                    System.out.println("**MARK FAV CLICKED");
                    break;
    
    
                }
            }
    

    In the above getView method Do Change the ImageView to checkbox and refer it to the corresponding checkbox id in your row.xml Also implement your BaseAdapter Class with onCLickListener so that you would be able to get the onClick method in that base adapter class.

    Hope you get my point. For any confusion Ask ME..

    Thanks
    sHaH

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

Sidebar

Related Questions

I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
Currently I have a list view within it each row has a checkbox attached.
I currently have 4 textboxes, 1 checkbox and a dropdownlist. I am attempting to
Currently I have a UITextView field with the CheckBox Detect Links checked. The contents
Currently we have a table with a bunch of data from a database which
I have a ListView that contains 3 checkboxes per row. I want to set
I have a listview with each row having a checkbox, imageview and text view
I have a ListView of items that need to be checkable/uncheckable. I have set
I currently have two arrays that look like this: Swatches: Array ( [0] =>
I have a listview which loads its data from sqlite database. Each row in

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.