Title: what is difference between use of boolean array and class object with list in baseadapter class
Tags: android;listview;arraylist;boolean;android-viewholder
Question: i am using check-box with list view by extending base adapter class to "cust_listadapter"(custom adapter). in this when i am using boolean array to save selection of check-box then code is running fine, but when i used objects(beans) with Array List, then code is not running correctly.whenever i select a check box then all check boxes seen select.
    below,i have  shown my code.

```     public class MainActivity extends Activity {
    ListView l1;
    cust_listadapter custom_adapter;
    List<Integer&gt; l_items;
    List<State_Refresh&gt; check_state;
    State_Refresh ob_state;

    Boolean b_check[]=new Boolean[50];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        l_items=new ArrayList<Integer&gt;();
        ob_state=new State_Refresh();
        check_state=new ArrayList<State_Refresh&gt;();

        for(int i=1;i<=50;i++)
        {
            l_items.add(i);
            b_check[i-1]=false;
            ob_state.setState(false);
            ob_state.setButtonValue("OFF");
            check_state.add(ob_state);

        }
        l1=(ListView) findViewById(R.id.list1);

        custom_adapter=new cust_listadapter();

        l1.setAdapter(custom_adapter);


        l1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?&gt; arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "huluhulu   "+arg2, 0).show();



            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    class cust_listadapter extends BaseAdapter
    {

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

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

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




        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            final View_Holder viewHolder;
            if(convertView==null)
            {

                 convertView=getLayoutInflater().inflate(R.layout.list_items,null);
             viewHolder=new View_Holder();
             viewHolder.ch1=(CheckBox) convertView.findViewById(R.id.check_box1);
             viewHolder.tv1=(TextView) 
                         convertView.findViewById(R.id.textview1);      
             viewHolder.ch1.setFocusable(false);
             viewHolder.ch1.setFocusableInTouchMode(false);         
                 convertView.setTag(viewHolder);
                 viewHolder.ch1.setTag(check_state.get(position).getState());
            }
            else
            {


                viewHolder=(View_Holder) convertView.getTag();
                viewHolder.ch1.setChecked(check_state.get(position).getState());
                //getting value from boolean array
                               // viewHolder.ch1.setChecked(b_check[position]);

            }


            viewHolder.ch1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub  
                    if(viewHolder.ch1.isChecked())
                    {
                        check_state.get(position).setState(true);   
                        b_check[position]=true;
                                        }
                    else
                    {
                        b_check[position]=false;
                        check_state.get(position).setState(false);
                    }


                }
            });



            return convertView;
        }


    }

    class View_Holder
    {
        CheckBox ch1;
        TextView tv1;

    }

    class State_Refresh
    {
        Boolean check_value;

        public void setState(Boolean check_value)
        {
            this.check_value=check_value;
        }
        public Boolean getState()
        {
            return check_value;
        }


    }
}
```



Here is another answer: Set the position as tag for every line, read it in the listener:

```public View getView(final int position, View convertView, ViewGroup parent) {

        final View_Holder viewHolder;
        if(convertView==null)
        {

             convertView=getLayoutInflater().inflate(R.layout.list_items,null);
             viewHolder=new View_Holder();
             viewHolder.ch1=(CheckBox) convertView.findViewById(R.id.check_box1);
             viewHolder.tv1=(TextView) 
                     convertView.findViewById(R.id.textview1);      
             viewHolder.ch1.setFocusable(false);
             viewHolder.ch1.setFocusableInTouchMode(false);         
             convertView.setTag(viewHolder);
             viewHolder.ch1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub  
                int pos = (Integer)v.getTag();
                check_state.get(pos).setState(((CheckBox)v).isChecked());
                b_check[pos]=((CheckBox)v).isChecked();
            }
        });

        }
        else
        {


            viewHolder=(View_Holder) convertView.getTag();
        }

        viewHolder.ch1.setTag(position);
        viewHolder.ch1.setChecked(check_state.get(position).getState());

        return convertView;
    }
```

Btw. please do not code the variable type in the variable name. b_check[] should be check[]. 

Comment for this answer: thanks for answering my question. i applied your code in my project, but still i faced same problem.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:06/13/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><listview><arraylist><boolean><android-viewholder>', 'Title': 'what is difference between use of boolean array and class object with list in baseadapter class', 'ViewCount': 178, 'id': 24202358, 'user_AboutMe': None, 'user_AccountId': 3016168.0, 'user_DisplayName': 'Akashsingla19', 'user_Reputation': 682.0, 'user_Views': 78.0, 'user_id': 2558284.0}}