code: protected final int getNumColumnsCompatible() {
          try {
              Field numColumns = GridView.class.getDeclaredField("mNumColumns");
              numColumns.setAccessible(true);
              return numColumns.getInt(this);
          } catch (Exception e) {
              throw new RuntimeException("Unable to retrieve number of columns", e);
          }
      }
docs: Returns the number of the grid view's columns by either using the
  <code>getNumColumns</code>-method on devices with API level 11 or greater, or via reflection
  on older devices.
  
  @return The number of the grid view's columns as an {@link Integer} value or {@link
  #AUTO_FIT}, if the layout is pending