Every seventh box checked with CheckBoxes in ListView

后端 未结 2 1411
無奈伤痛
無奈伤痛 2021-01-27 00:49

I have a ListView that has 649 entries. Each View in the list has two LinearLayouts, an ImageView, a few TextViews, and a CheckBox. I currently have code to go through all the C

2条回答
  •  情深已故
    2021-01-27 01:00

    I was also facing a similar king of problem, so after lot of reading I solved this problem like this:

    @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.listview, null);
                holder = new ViewHolder();
                holder.nameView = (TextView)convertView.findViewById(R.id.textView1);
                holder.numberView = (TextView)convertView.findViewById(R.id.textView2);
                holder.cb = (CheckBox)convertView.findViewById(R.id.checkBox1);
                convertView.setTag(holder);                
            } else {
                holder = (ViewHolder)convertView.getTag();
            }
            holder.nameView.setText(mData.get(position).toString());
            holder.numberView.setText(mNumber.get(position).toString());
            holder.cb.setChecked(false);
            holder.cb.setTag(position);
    
    
    
            if(selected.indexOf(mNumber.get(position).toString()) >= 0)
            {
    
            holder.cb.setChecked(true);
            }
    
            return convertView;
        }
    
    }
    

    Here what I am doing that on getView() I am unchecking all the checkboxes and checking again manually those which I need to be checked according to the textview it corresponds. So if the user scroll down after checking the first checkbox, all the checkbox in the view will get unchecked and if he again scrolls up then also all the checkboxes will be unchecked but then the one he clicked before will be again rechecked.

提交回复
热议问题