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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:51:44+00:00 2026-06-17T19:51:44+00:00

i have a listview with checkbox on each row , when i select any

  • 0

i have a listview with checkbox on each row , when i select any checkbox and then scroll the screen , the checkboxes for each item changed ranomally , i mean the uncheck it becomse check and sometimes it stay uncheck , and then when i scroll up again , the checked one becomes uncheck , i found this question Android listview with checkbox problem , and the users says it helps them, but i can’t understand what sholud i do , and help please

this is my adapter

class RestaurantAdapter extends BaseAdapter {
    private static LayoutInflater inflater = null;
    private ArrayList<HashMap<String, String>> data;
    Activity activity;

    public RestaurantAdapter(Activity activity,
            ArrayList<HashMap<String, String>> data) {
        // TODO Auto-generated constructor stub
        this.activity = activity;
        this.data = data;
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View vi = convertView;
        if (vi == null)
            vi = inflater.inflate(R.layout.restaurant_multi_select_list_item,
                    null);
        TextView name = (TextView) vi
                .findViewById(R.id.restaurant_multi_select_title);
        ImageView image = (ImageView) vi
                .findViewById(R.id.restaurant_multi_select_list_item_image);
        CheckBox cb = (CheckBox) vi
                .findViewById(R.id.restaurant_multi_select_checkBox);
        HashMap<String, String> restaurant = data.get(position);
        name.setText(restaurant.get("name"));

        image.setImageResource(Integer.parseInt(restaurant.get("image")));
        return vi;

    }
}
  • 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-17T19:51:45+00:00Added an answer on June 17, 2026 at 7:51 pm

    It is about cycle and recycle the elements in the listview , take a look at converView concept.

    i edit your code and added a status array to keep saving the last value of each checkbox and load it in every cycle and recycle,

    class RestaurantAdapter extends BaseAdapter {
        private ArrayList<Boolean> status = new ArrayList<Boolean>();
        private static LayoutInflater inflater = null;
        private ArrayList<HashMap<String, String>> data;
        Activity activity;
    
        public RestaurantAdapter(Activity activity,
                ArrayList<HashMap<String, String>> data) {
            // TODO Auto-generated constructor stub
            this.activity = activity;
            this.data = data;
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            for (int i = 0; i < data.size(); i++) {
                status.add(false);
            }
        }
    
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return data.size();
        }
    
        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View vi = convertView;
            if (vi == null)
                vi = inflater.inflate(R.layout.restaurant_multi_select_list_item,
                        null);
            TextView name = (TextView) vi
                    .findViewById(R.id.restaurant_multi_select_title);
            ImageView image = (ImageView) vi
                    .findViewById(R.id.restaurant_multi_select_list_item_image);
            CheckBox cb = (CheckBox) vi
                    .findViewById(R.id.restaurant_multi_select_checkBox);
            cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    if (isChecked) {
                        status.set(position, true);
                    } else {
                        status.set(position, false);
                    }
                }
            });
            cb.setChecked(status.get(position));
            HashMap<String, String> restaurant = data.get(position);
            name.setText(restaurant.get("name"));
    
            image.setImageResource(Integer.parseInt(restaurant.get("image")));
            return vi;
    
        }
    }
    

    not that you have to use setOnCheckedChangeListener on the getview , not on the listview

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

Sidebar

Related Questions

In an ASP:ListView control, I have a checkbox for each row. Each row represents
I have listview with 2 textbox and 1 checkbox on each row. I want
I have a listview with a checkboxes in each row. I am using the
I have a ListView where each item has a checkbox. Initially there are no
I have a ListView that have in each row 2 TextView and a CheckBox.
I have a listView multichoice, Each row of list have a checkbox. And I
I have a custom adapter populating a listview. Each row has a checkbox which
I have created listview using layoutinflator. Listview contains checkbox and textview for each row.
I have a listview and each Item has a CheckBox control as part of
I have a listview with each row having a checkbox, imageview and text view

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.