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

The Archive Base Latest Questions

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

I have a ListView adapter where I am writing the ListItems from an XML.

  • 0

I have a ListView adapter where I am writing the ListItems from an XML. I want to flag when an item is checked and unflag it when an item is unchecked. I am using an array for storing the flag values. For Example if my ListView has four list items “Red, Blue, Green, Yellow”. If Red and Green are checked, the array should be updated to [1, 0, 1, 0] and if they are unchecked it should be updated to [0, 0, 0, 0]. Below is my code. I did something wrong and it is not displaying the desired output. Can someone look into it and suggest me a better way to solve it. Thank you!

ArrayAdapter<String> adapter;

    array =  getResources().getStringArray(R.array.facilities);
    strings1 = new ArrayList(Arrays.asList(array));

    TopicSelectionListAdapter topicSelectionListAdapter = new TopicSelectionListAdapter(
            second.this, R.layout.listrow, strings1);
    listView.setAdapter(topicSelectionListAdapter);
    listView.setItemsCanFocus(false);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    for(int i=0;i<strings1.size();i++){
        listView.setItemChecked(i, false);
    }

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position,
                long arg3) {
            CheckedTextView selectedItem = (CheckedTextView) view;
            boolean isChecked = selectedItem.isChecked();

            Log.e("TAG","item clicked position = " + position + " isChecked = " + isChecked);
            for(int i=0; i< strings1.size(); i++){
                if(!isChecked){
                    bArray[i]= 0;
                }
                else{
                    bArray[i]= 1;
                }


            }
            for(int i =0; i < bArray.length; i++){
                Log.e("TAG","boolean Array value = " + bArray[i]);
            }


        }
    });
  • 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:42:05+00:00Added an answer on June 17, 2026 at 7:42 pm

    this part simply ticks each part of your bArray

      for(int i=0; i< strings1.size(); i++){
          if(!isChecked){
              bArray[i]= 0;
          }
          else{
             bArray[i]= 1;
          }
      }
    

    the reason for this is, you simply wiping your whole array without checking if the element of bArray for this particular event checked or not…
    doing this should result something better:

    bArray[position] = isChecked?1:0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview connected to a custom array adapter. This list shows information
Currently I'm using ActionBarSherlock and custom ListView Adapter, but I have this strange case
I have listview with some listadapter after click on item from list I'd like
I have a ListView with an adapter extending BaseAdapter. I create a view (from
I have a ListView where I want each item to have an ID number
I have a listView with an adapter loading images from URLs through a ImageLoader
I want to have a Listview adapter where each rows uses it's own convertview,
I want to have a list of elements (using a ListView) and each element
In android, i have listview and inside the listview adapter,i want to use some
I have ListView with custom adapter extends ArrayAdapter. Each item is object: public class

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.