1. Are you ready for the Galaxy S20? Here is everything we know so far!

Access data from non visible children in GridView

Discussion in 'Android Development' started by CIOC, Apr 18, 2020.

  1. CIOC

    CIOC Lurker
    Thread Starter

    I have a GridView with some images, each image also have a checkbox associated with it, I'm trying to check the state of all checkboxes, for that I have this code:

    Code (Java):
    1. for (int i = 0; i < gridView.getChildCount(); i++) {
    2.    View child = gridView.getChildAt(i);
    3.    CheckBox checkBox = (CheckBox) child.findViewById(R.id.checkBox);
    4.  
    5.    if(checkBox.isChecked())
    6.        // do something
    7. }
    I know that gridView.getChildCount() returns only the visible items, I can also get the count from the adapter like this gridView.getCount() but of couse that will throw an null pointer exception when trying to access the checkbox as that object does not exists if it's not visible.

    Is there a way to access the checkbox even when the image is not visible?
     


Loading...

Share This Page

Loading...