Skip to content

Instantly share code, notes, and snippets.

View ShivamPokhriyal's full-sized avatar

Shivam Pokhriyal ShivamPokhriyal

  • Twilio
  • Rishikesh
View GitHub Profile
@ShivamPokhriyal
ShivamPokhriyal / OTPEditText.java
Created November 27, 2020 15:03
A custom view to handle otp input in multiple edittexts. It will move focus to next edittext, if available, when user enters otp and it will move focus to the previous edittext, if available, when user deletes otp. It will also delegate the paste option, if user long presses and pastes a string into the otp input.
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;