Android - How to get all the childrens under the custom listview even if we perform scrolling
<p>I have a custom listview adapter with a checkbox,imageview, textview. and i also have a button and a checkbox(for select all) in my main layout(not in listview).</p>

<p>What here i want is to check all these listview checkboxes at once when i check my main layout's checkbox.And I want to get that related textview id as dynamically.</p>

<p>i tried few techniques using getChaildAT(i).but it's not working with my code.with this i'm able to check/uncheck only particular visible group of checkboxes.While scroll down to list it get failed.</p>

<p>My aim is to check/uncheck all the checkboxes even with scroll and get the related id's.So Pls provide any other way to get all the children count in that custom list view.</p>

<p>In main activity I've custom adapter code like this</p>

<pre><code>filterlist.setAdapter(new CustomAdptr(this));
class CustomAdptr extends ArrayAdapter {
        Activity context;
        String[] eventtypename;
        CustomAdptr(Activity context) {
            super(context, android.R.layout.simple_list_item_multiple_choice, filterListdata);
            rowView.clear();
            this.context = context;
        }
        public View getView(final int position, View convertView, ViewGroup parent) {
            View viewrow = convertView;
            if (viewrow == null) {
                LayoutInflater inflater = context.getLayoutInflater();
                viewrow = inflater.inflate(R.layout.filterlistrow, null);
            }
            ImageView iw = (ImageView)viewrow.findViewById(R.id.img);
            try {
                String image = filterListdata.get(position).getFilterImg();
                byte[] imbbyte = com.cincinnati.parks.Base64.decode(image);;
                Bitmap bmp=BitmapFactory.decodeByteArray(imbbyte,0,imbbyte.length);
                iw.setImageBitmap(bmp);
            }catch (Exception e) {
                e.printStackTrace();
            }
            TextView tv = (TextView)viewrow.findViewById(R.id.title);
            tv.setText(filterListdata.get(position).getFilterImageName());
            final CheckBox chkbx = (CheckBox)viewrow.findViewById(R.id.checkbox);
            chkbx.setChecked(true);
            TextView selectedid = (TextView)viewrow.findViewById(R.id.rid);
            selectedid.setText(String.valueOf(filterListdata.get(position).getFilterImgId()));
            rowView.add(viewrow);
            viewrow.setClickable(true);
            viewrow.setFocusable(true);
            checkboxImagelist.clear();
            for(int i=0;i&lt;filterListdata.size();i++) {
                checkboxImagelist.add(filterListdata.get(i).getFilterImgId());
            }
            chkbx.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (chkbx.isChecked()) {
                        FilterImageId.clear();
                        checkboxImagelistall.clear();
                        topOkbuttongray.setVisibility(4);
                        topOkbutton.setVisibility(0);
                        rb = (CheckBox) v;                           
                        FilterImageId.add(filterListdata.get(position).getFilterImgId());
                        checkboxImagelist.addAll(FilterImageId);
                        checkboxImagelistall.addAll(FilterImageId);
                    }else {
                        FilterImageId.clear();
                        FilterImageId.add(filterListdata.get(position).getFilterImgId());
                        checkboxImagelistall.remove(FilterImageId);
                        checkboxImagelist.removeAll(FilterImageId);
                        if((checkboxImagelist.size()) == 0){
                            topOkbuttongray.setVisibility(0);
                            topOkbutton.setVisibility(4);
                        }
                        if (filterListdata.size() != checkboxImagelist.size()) all.setChecked(false);
                    }
                    if (filterListdata.size() == heckboxImagelist.size()) all.setChecked(true); 
                }
            });
            return (viewrow);
        }
    }
</code></pre>

<p>The below code is for check all button</p>

<pre><code>OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {

int Id;
System.out.println("enter set all button");
rb = (CheckBox) v;
if(rb.isChecked()) {
System.out.println("enter set all button rb.isChecked()");
topOkbutton.setVisibility(0);
topOkbuttongray.setVisibility(4);
checkboxImagelistall.clear();
checkboxImagelist.clear();
//markAll(true); 
for(int i=0;i&lt;filterListdata.size();i++) {
Id = filterListdata.get(i).getFilterImgId();
checkboxImagelistall.add(Id);
checkboxImagelist.add(Id);
}
System.out.println("In enable condition filterlist.getChildCount()============="+filterlist.getChildCount());
System.out.println("In enable condition filterlist.getAdapter().getCount()============="+filterlist.getAdapter().getCount());
/*for(int i=0; i &lt; filterlist.getAdapter().getCount(); i++){*/
for(int i=0; i &lt; filterlist.getChildCount(); i++){
LinearLayout itemLayout = (LinearLayout)filterlist.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.checkbox);
//CheckBox cb = (CheckBox)filterlist.getAdapter().getView(i, null, null);
cb.setChecked(true);
TextView tv = (TextView)filterlist.getChildAt(i).findViewById(R.id.rid);
rowIdstr.add(tv.getText().toString());
}
}else {
System.out.println("enter set all button rb.isChecked() Not");
all.setChecked(false);
rb.setChecked(false);
topOkbutton.setVisibility(4);
topOkbuttongray.setVisibility(0);
System.out.println("In disable condition filterlist.getChildCount()============="+filterlist.getChildCount());
System.out.println("In disable condition filterlist.getAdapter().getCount()============="+filterlist.getAdapter().getCount());
//markAll(false); 
for(int i=0; i &lt; filterlist.getChildCount(); i++){
//CheckBox cb = (CheckBox)filterlist.getAdapter().getView(i, null, null);
LinearLayout itemLayout = (LinearLayout)filterlist.getChildAt(i);
CheckBox cb = (CheckBox)itemLayout.findViewById(R.id.checkbox);
cb.setChecked(false);
rowIdstr.clear();
checkboxImagelistall.clear();
}
}
}
};
all.setOnClickListener(radio_listener);
</code></pre>

<p>And I used below .xml files for custom listing
for check all button in main layout I used this</p>

<pre><code>&lt;CheckBox  android:id="@+id/radioselectall" 
   android:layout_width="30dp"  android:layout_height="20dp" 
   android:layout_marginLeft="10dp" android:layout_marginTop="4dp"
   android:layout_marginRight="10dp" android:checked="true" /&gt;
</code></pre>

<p>And the listview is</p>

<pre><code>&lt;ListView 
android:id="@+id/listm" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_marginLeft="10dp" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>And another .xml file is</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
&gt;
    &lt;CheckBox
    android:layout_width="40dp"
    android:scaleType="centerCrop"
    android:id="@+id/checkbox"
    android:layout_height="40dp"
    android:layout_marginTop="4dp"
    android:checked="true"/&gt;
    &lt;ImageView
    android:id="@+id/img"
    android:scaleType="centerCrop"
    android:layout_marginLeft="30dp"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_gravity="left"/&gt;
    &lt;TextView
    android:layout_width="150dp"
    android:scaleType="centerCrop"
    android:id="@+id/title"
    android:layout_height="fill_parent"
    android:textStyle="normal"
    android:layout_marginTop="2dp"
    android:layout_marginLeft="30dp"
    android:textColor="@color/white"
    android:textSize="15sp"
    /&gt;
    &lt;TextView
    android:layout_width="wrap_content"
    android:id="@+id/rid"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="16sp" 
    android:visibility="invisible"
    /&gt;
&lt;/LinearLayout&gt;
</code></pre>
