1

what is the difference between returning super.getItemId(position) and just returning return position?

@Override
public long getItemId(int position) {
    return super.getItemId(position);
}

@Override
public long getItemId(int position) {
    return position;
}
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
subrata sharma
  • 344
  • 4
  • 17

1 Answers1

1

Read the explanation about super.

Calling super.getItemId(position) will call the getItemId method in the Recyclerview adapter class which will return -1 as

   /**
     * Return the stable ID for the item at <code>position</code>. If {@link #hasStableIds()}
     * would return false this method should return {@link #NO_ID}. The default implementation
     * of this method returns {@link #NO_ID}.
     *
     * @param position Adapter position to query
     * @return the stable ID of the item at position
     */
    public long getItemId(int position) {
        return NO_ID;
    }

so you must override getItemId method to send unique int ID(like return position) which will be used to find holders, children etc for animation, holder reusability and often during testing etc.

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68