code: public static int generateViewId() {
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
              return generateCompatViewId();
          } else {
              return View.generateViewId();
          }
      }
docs: While {@link View#generateViewId()} require API Level >= 17, this tool is compatibe with all API.
  
  According to current API Level, it decide weather using system API or not. So you can use {@link
  #generateViewId()} and {@link View#generateViewId()} in the
  same time and don't worry about getting same id.
  
  @return Id