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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:59:46+00:00 2026-05-31T01:59:46+00:00

I am having some serious trouble with getView in a ListView. The problem is,

  • 0

I am having some serious trouble with getView in a ListView. The problem is, that I have CheckBoxes on each row. I need to work with them – the ListView is part of TabHost and I need to remember which CheckBox was checked and use it in other tabs.

However, I also have a “master checkbox” that checks all of the checkboxes in the listview. No big deal, but the thing is, that I just can’t find out where I clicked to change the state of the CheckBox in ArrayList, where I keep all the states of the CheckBoxes. Everytime I assign listener to every View, the “int position” as an argument gives some weird number, definitely not the one I need – the position in the adapter, I bet it’s something like “position on the screen right now…”

Here is the code:

public View getView(int position, View convertView, ViewGroup parent) {
        count = position;
        View rowView = convertView;
        SingleCarView sView = null;

        if (rowView == null) {
            LayoutInflater inflater = activity.getLayoutInflater();
            rowView = inflater.inflate(R.layout.activity_overview_listview_row, null);
            sView = new SingleCarView();

            sView.cbx = (CheckBox)rowView.findViewById(R.id.overview_listview_chckbox);
            sView.carName = (TextView)rowView.findViewById(R.id.overview_listview_label);
            sView.state = (ImageView)rowView.findViewById(R.id.overview_listview_icon);
            rowView.setTag(sView);
        } else {
            sView = (SingleCarView) rowView.getTag();
        }
        // THE TROUBLE BEGINS HERE...
        sView.cbx.setChecked(savedState.get(position));
        sView.cbx.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(computerActionWithCheckBox) {
                    // nothing
                } else {
                    if(allCars.isChecked()) {
                        savedState.set(count, isChecked);
                        userModifiedCheckBox = true;
                        allCars.setChecked(false);

                        adapter.notifyDataSetChanged();
                    } else {
                        savedState.set(count, isChecked);
                    }
                }
            }
        });
        sView.carName.setText(objects.get(position));
        switch(DataLoaderBeta.par.carState.get(position)){
        case 1:
            sView.state.setImageResource(R.drawable.ic_moving);
            break;
        case 2:
            sView.state.setImageResource(R.drawable.ic_out_of_signal);
            break;
        case 0:
            sView.state.setImageResource(R.drawable.ic_parked);
            break;
        }
        return rowView;
    }

Thanks a lot for any answer! 🙂

  • 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-31T01:59:48+00:00Added an answer on May 31, 2026 at 1:59 am

    In the getView() method set as a tag for your CheckBox and integer representing the position you get from the getView() method:

    sView.cbx.setTag(new Integer(position));
    

    Then in your OnCheckedChangeListener you get the checkbox that was clicked , the buttonView parameter, and from this button get the tag getTag() and use that number for the position in the savedState:

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              Integer realPosition = (Integer) buttonView.getTag(); //realPosition will be the real position you get in the getView() method
    //other stuff here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some serious performance issues with a multi-million row table that I feel
I am having some serious problem here. When do we need a class exactly?
I'm having some serious trouble understanding the view matrix in XNA. I've come pretty
I am having some serious trouble creating a WPF TreeView with an Object databinding.
I've some pocket pc app and i'm having a serious problem with it described
I'm having some serious issues with a WinForm application that I'm working on. Currently,
I'm having serious trouble configuring my OpenLDAP server to have the memberOf overlay enabled.
I am having some serious pathing issues with a website that I am creating.
At my work we are currently having some serious pains pushing our database changes
I am not good with CSS and am having some serious issues. I have

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.