2012-01-11 5 views
0

키보드로 입력 할 때이 형식의 전화 번호 223-233-3334를 설정하고 싶습니다. .i 내가 dialerkeylistener와 textfilter를 사용해야한다는 것을 알고 있습니다. 누군가가 dialerkeylistener를 사용하는 방법을 샘플로 제공해야합니다. 안드로이드안드로이드에서 dialerkeylistener를 사용하는 방법

감사

사용자 입력, 당신은 다음과 같은 몇 가지 해결 방법을 사용할 수 있지만 서식 전화 번호를 구현하는 비 NANP (http://www.howtocallabroad.com/nanp.html) 국가에 대한

답변

1

을의 설정 형식 :

yourEditText.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

       String typedNum = yourEditText.getText().toString(); 
       if(typedNum.length() == 3) 
       { 
        yourEditText.setText(typedNum + "-"); 
       yourEditText.setSelection(4); 
       } 
       else if(typedNum.length() == 7) 
       { 
        yourEditText.setText(typedNum + "-"); 
        yourEditText.setSelection(8); 
       } 

      } 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, 
        int after) { 
      } 
      @Override 
      public void afterTextChanged(Editable s) { 
      } 
     }); 

그렇지 않으면 그렇습니다 기술인 것은 다음과 같습니다

import android.telephony.PhoneNumberFormattingTextWatcher; 

에서 OnCreate :

yourEditText.addTextChangedListener(new PhoneNumberFormattingTextWatcher()); 

사용자가 전화 번호를 입력 한 후 숫자의 형식을 좋아한다면 :

import android.telephony.PhoneNumberUtils; 

에서 OnCreate :

PhoneNumberUtils.formatNumber(Editable text, int defaultFormattingType); 
+0

sharma 에뮬레이터에서 작동하지만 장치 설정이 휴대 전화에서 작동하지 않는 경우 – kumar

+0

편집 된 답변을 참조하십시오. 귀하의 요구 사항에 대한 해결 방법을 만들었습니다. 나는 그것이 당신을 도울 것이기를 바랍니다. –

+0

죄송합니다,이 질문의 제목을 읽었습니까? 나는 네 대답이 예상 한 것 같지 않아. –

관련 문제