2013-02-22 1 views
0

내 응용 프로그램에서 EditField를 사용하여 DIAL에 전화 번호를 입력하고 있습니다.Android의 첫 번째 입력 문자를 기반으로 EditField에서 자릿수 제한을 변경 하시겠습니까?

지금 내 쿼리

1) if begins with 1, it should be only 10 max digits after the 1, 

2) if 011, up to 15 digits max, but no fewer than 8 after 011. 

날이이 EditField에서 수행 할 수있는 방법을 알려 주시기 바랍니다있다.

+1

확인이 링크 http://marakana.com/forums/android/ 도움이 알려줘 같은 코드를 변경할 수 있습니다 edittext에 textwatcher를 적용하기위한 learning_android_book/487.html이 도움이 될 수 있습니다. 자신 만의 논리를 작성하십시오 –

답변

1

텍스트를 편집 텍스트에 추가하고 최대 한도를 변경하십시오.

0

여기에 해결책이 있습니다. 그것의 매우 가난한 솔루션 다만 힌트 유형은 그러나 당신은 당신에 따라

final int LIMIT_FIRST = 10; 
     final int LIMIT_SECOND = 15; 
     final EditText et = (EditText) findViewById(R.id.edittext); 
     et.setSingleLine(); 
     et.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       String stringValue = s.toString().trim(); 
       int stringLength = stringValue.length(); 
       if(stringLength == 0){ 
        InputFilter[] FilterArray = new InputFilter[1]; 
        FilterArray[0] = new InputFilter.LengthFilter(1000); 
        et.setFilters(FilterArray); 
       }else if(stringLength == 1){ 
        if(stringValue.equalsIgnoreCase("1")){ 
         InputFilter[] FilterArray = new InputFilter[1]; 
         FilterArray[0] = new InputFilter.LengthFilter(LIMIT_FIRST); 
         et.setFilters(FilterArray); 
        } 
       }else if(stringLength == 3){ 
        if(stringValue.equalsIgnoreCase("011")){ 
         InputFilter[] FilterArray = new InputFilter[1]; 
         FilterArray[0] = new InputFilter.LengthFilter(LIMIT_SECOND); 
         et.setFilters(FilterArray); 
        } 
       } 
       System.out.println(s); 
      } 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, 
        int after) { 
       System.out.println(s); 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       System.out.println(s); 
      } 
     }); 

이 당신에게

+0

우수 제안 Abhinav Singh Maurya ..... !!! :) thankx –

+0

Wellcome 내 친구 만약 당신이 나를 찾을 수있는 더 많은 도움이 필요하십니까 :) –