Rohit Sharma Rohit Sharma - 6 months ago 50
Android Question

Disable 0 key on softkeyboard for first time

I want to disable the number

key on soft keyboard for first time when an user clicks on

has an
input type
and i have to input a ten digit phone number where the first digit should not be zero.

Please suggest me how to achieve this?

Answer Source
    boolean changing = false;

    EditText edit = (EditText)findViewById(;
    edit.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
             if (!changing && edit.getText().toString().startWith("0")){
                changing = true;
                edit.setText(edit.getText().toString().replace("0", ""));
             changing = false; 

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        public void onTextChanged(CharSequence s, int start, int before, int count) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download