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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:51:20+00:00 2026-06-12T15:51:20+00:00

I have the code below, now I need to keep track of the checkbox

  • 0

I have the code below, now I need to keep track of the checkbox state in each gridview item, and fetch that info on a button click to update the information. My button event in the calling activity of imageadapter for a gridview.

    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        ImageView imgView = null;

            if (convertView == null) {

                holder = new ViewHolder(); 
                LayoutInflater ltInflate = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); 
                convertView = ltInflate.inflate(R.layout.griditem, null);

                holder.textview1 = (TextView) convertView.findViewById(R.id.grid_item_alert_date);
                holder.textview2 = (TextView) convertView.findViewById(R.id.grid_item_alert_time);
                holder.textview3 = (TextView) convertView.findViewById(R.id.grid_item_alert_type);

                holder.imageview    = (ImageView) convertView.findViewById(R.id.grid_item_image);
                holder.checkbox = (CheckBox) convertView.findViewById(R.id.checkbox_ack);
                convertView.setTag(holder);

            }
            else
            {   
                holder = (ViewHolder) convertView.getTag();
            }

            holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                  @Override
                  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
                {

                    //Accessing or saving position to a List doesn't work here

                    //How to add ? info to a list here...

                }

                  } });

            holder.textview1.setText("Text 1 ");
            holder.textview2.setText("Text 2 ");
            holder.textview3.setText("Text 3 ");
            holder.checkbox.setChecked(false);
            holder.imageview.setImageBitmap(bitmap);
            holder.id = position;

            return convertView;
    }

In the activity:

private OnClickListener UpdateButtonListener =
            new OnClickListener(){
            public void onClick(View v)
            {
            //CheckBox ckbocx = (CheckBox) findViewById(R.id.checkbox_ck);
                        //Need info on all the checkboxes for each gridview item

    };

Any clues, hints are more than welcome.

  • 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-06-12T15:51:21+00:00Added an answer on June 12, 2026 at 3:51 pm

    Deal with integer array to store the state of your checkboxes when it checked/unchecked,
    Initially fill the array with 0 values which indicate unchecked of your checkboxes like this.

    int[] checkStates;
     checkStates = new int[datalist.length()];
       for (int i = 0; i < datalist.length(); i++) {
            checkStates[i] = 0;
       }
    

    Now handle checkboxes click event to get perfect position. use settag & get gettag and inside click event when box get selected change the value of particular position to 1 from 0.

    Like this#

      checkbox.setTag(position);
    
    
    
        checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                pos = (Integer) buttonView.getTag();
                // checkStates[pos] = 1;
                // pos = (Integer) v.getTag();
    
                if (!buttonView.isChecked()) {
                    boxState[pos] = 0;
                } else {
                    boxState[pos] = 1;
                }
                notifyDataSetChanged();
            }
        });
    

    and inside getview method handle your check/uncheck state this way..

    if (checkStates[position] == 0) {
                checkbox.setChecked(false); // set unchecked"
            } else {
                checkbox.setChecked(true); // set checked"
            }
    

    This way you will get the info of checkboxes which are selected, further handle your button click event, and get the int array which filled while check and uncheck.

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

Sidebar

Related Questions

The code shows below what i have done till now. Now what i need
Edit: original question below, but I revise it now that I have some code
I have the code below which I now need to figure out how to
I have the code below. It looks long and complicated and now I have
I have code that looks more or less like the code below but it
I have this code below. I need to use a class id instead of
I have code below, where i need to get the return value in a
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have code as below: var s : String = hello world var 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.