0

사용자가 편집 텍스트에 입력 한 각 숫자 세트 뒤에 $를 추가해야합니다. 예를 들어, 사용자가 숫자를 입력하자마자 $가 그 번호 앞에 자동으로 위치해야합니다. 나는 현재 문자열을 얻은 다음 $를 추가하고 edittext의 텍스트를 설정하여 텍스트 워처를 사용하려고했습니다. 내가 그렇게하면 키보드가 얼어 버린다.edittext에서 각 단어 뒤에 문자 추가

+0

Impement을 A [textwatcher] (http://developer.android.com/reference/android/text/TextWatcher. html) –

+0

텍스트 워처의 코드를 게시 할 수 있습니까? 일반적인 실수는 텍스트를 다시 변경하는 onTextChanged를 발생시키는 텍스트 워처 내의 'EditText'에서 텍스트를 변경하는 것입니다. 루프를 입력했을 수도 있습니다. 텍스트 워처'yourEditText.removeTextChangedListener (this);'를 먼저 제거하고 변경 한 다음'onEditText.addTextChangedListener (this);에있는 텍스트 워처를 다시 추가해야합니다 - 모두'onTextChanged' 메소드 안에 있습니다. – CodeMonkey

답변

-1

onTextChanged 방법 안에 무한 루프를 입력 한 것처럼 들립니다. 당신은 리스너 다시 추가 한 후, 다음 변경을 먼저 리스너를 제거해야합니다

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

     // Remove TextChangedlistener so that this function does not 
     // enter an infinite loop when we change it in code! 
     yourEditText.removeTextChangedListener(this); 

     // Add your code to insert the '$' symbol here 


     // Re-add listener 
     yourEditText.addTextChangedListener(this); 
     // This just moves the cursor back to the end of the input 
     yourEditText.setSelection(editText.getText().length()); 

    } 
관련 문제