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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:18:03+00:00 2026-05-18T05:18:03+00:00

Sorry to make people confused. I simplified the question, which is the checkbox. Basically

  • 0

Sorry to make people confused. I simplified the question, which is the checkbox. Basically I want a listview like this, I want the checkbox be toggled when clicked.

[textview][checkbox]

[textview][checkbox]

[textview][checkbox]

[textview][checkbox]

The problem is the checkbox cannot work correctly. When I clicked a checkbox, it never be toggled.

Could anyone gives any suggestion? Thank you.

This is my codes right now:

public class MyAdapter extends SimpleAdapter {

    Map<Integer, Boolean> map;

    LayoutInflater mInflater;

    private List<? extends Map<String, ?>> mList;

    public MyAdapter(Context context, List<Map<String, String>> data, int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        map = new HashMap<Integer, Boolean>();
        mInflater = LayoutInflater.from(context);
        mList = data;
        for (int i = 0; i < data.size(); i++) {
            map.put(i, false);
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.rapid_diagnosis_row, null);
        }
        TextView textView = (TextView) convertView.findViewById(R.id.multiple_question);
        textView.setText((String) mList.get(position).get("value"));

        CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.multiple_checkbox);
        checkBox.setChecked(map.get(position));

        // save position and checking status into tag
        checkBox.setTag(new int[] { position, checkBox.isChecked() == true ? 1 : 0 });

        checkBox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                // get position and checking status from tag, works fine
                int[] tag = (int[]) (v.getTag());
                int p = tag[0];
                int c = tag[1];

                // try to get checking status from the clicked view, not works
                // which is always true
                boolean checked = ((CheckBox) v).isChecked();
                // try to toggle the clicked (checkbox) view, not works
                // the checkbox pressed never be toggled
                ((CheckBox) v).toggle();

                // save status into a hashmap, works fine
                mSimpleAdapter.map.put(p, (c == 1 ? true : false));
            }
        });

        return convertView;
    }
  • 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-18T05:18:03+00:00Added an answer on May 18, 2026 at 5:18 am

    I solved this problem by replace the following toggle() line:

    public void onClick(View v) {
            // ((CheckBox) v).toggle();
            boolean checked = ((CheckBox) v).isChecked();
            if (checked) {
                ((CheckBox) v).setChecked(true);
            } else {
                ((CheckBox) v).setChecked(false);
            }
        }
    

    However I still don’t understand why toggle() cannot works.

    Thank you guys.

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

Sidebar

Related Questions

Sorry if this sounds like a really stupid question, but I need to make
I'm sorry this is a very long question. I'm looking for help from people
Sorry google translate make mistake, to many mistake, i want make an alarm in
Sorry if this doesn't make any sence, but I'm trying my best to understand
Sorry if the title doesn't make sense. Basically I have a series of strings
Sorry if this question is framed incorrectly. I am working on an iPad application
Sorry for the long title, didn't want people just reading the title and not
I'm sorry if this thread will be considered as subjective, but my question is
Hello for all people... Sorry for my english, but speak spanish... In this week,
I wasn't sure how to word the question for this topic...sorry. I'm just starting

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.