안드로이드

[ Android ] EditText TextWatcher 키입력 이벤트 [ 펌]

SojuMan 2012. 2. 29. 17:02


EditText mXMLBuyCount = null;
mXMLBuyCount = (EditText)findViewById(R.id.etBuyCount);

//선언
TextWatcher watcher = new TextWatcher()
{
    @Override
    public void afterTextChanged(Editable s) {
         //텍스트 변경 후 발생할 이벤트를 작성.
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after)
    {
         //텍스트의 길이가 변경되었을 경우 발생할 이벤트를 작성.
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count)
    {
         //텍스트가 변경될때마다 발생할 이벤트를 작성.
         if (mXMLBuyCount.isFocusable())
         {
             //mXMLBuyCount EditText 가 포커스 되어있을 경우에만 실행됩니다.
         }
    }
}

//호출
mXMLBuyCount.addTextChangedListener(watcher);