Adicionar automaticamente traço no número de telefone no Android

Em vez de 5118710, deve ser511-8710. Gostaria de adicionar um traço após o usuário que o usuário inseriu 3 dígitos já no EditText. O tamanho máximo do EditText é de apenas 7 dígitos.

Depois que eu descobri o problema acima, fiquei preso na codificação novamente. Quando eu já inseri 3 dígitos, ele acrescenta dash (é isso que eu gostaria de acontecer), mas o meu problema aqui é que os próximos 3 dígitos também acrescentam(Como isso:511-871-)... Por favor me ajude com isso. obrigado!

    txt_HomeNo.addTextChangedListener(new TextWatcher() {

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

            boolean flag = true;
            String eachBlock[] = txt_HomeNo.getText().toString().split("-");
            for (int i = 0; i < eachBlock.length; i++) {
                if (eachBlock[i].length() > 3) {
                    flag = false;
                }
            }

            if (flag) {

                txt_HomeNo.setOnKeyListener(new OnKeyListener() {

                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {

                        if (keyCode == KeyEvent.KEYCODE_DEL)
                            keyDel = 1;
                        return false;
                    }
                });

                if (keyDel == 0) {

                    if (((txt_HomeNo.getText().length() + 1) % 4) == 0) {

                        if (txt_HomeNo.getText().toString().split("-").length <= 3) {
                            txt_HomeNo.setText(txt_HomeNo.getText() + "-");
                            txt_HomeNo.setSelection(txt_HomeNo.getText().length());
                        }
                    }
                    a = txt_HomeNo.getText().toString();
                } else {
                    a = txt_HomeNo.getText().toString();
                    keyDel = 0;
                }

            } else {
                txt_HomeNo.setText(a);
            }

        }

questionAnswers(7)

yourAnswerToTheQuestion