특수 문자 입력 제한.
// 와처 등록
EditText ed = (EditText) find...;
ed.addTextChangedListener( watcher );
// 와처 정의
TextWatcher warcher = new TextWatcher() {
String text;
// 텍스트 변경시 특수문자 여부 검사
public void afterTextChanged(Editable arg0) {
int length = arg0.toString().length();
if( length > 0 ) {
Pattern ps = Pattern.compile("^[a-zA-Z0-9]+$");
if( !ps.matcher(arg0).marches() ) {
ed.setText(text);
ed.setSelection(ted.length());
}
}
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
text = arg0.toString();
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
};
'프로그래밍 > Android' 카테고리의 다른 글
| [안드로이드TV] 개발 전 확인사항 (0) | 2014.02.17 |
|---|---|
| GoogleTV 개발환경 설정 (0) | 2014.02.06 |
| GCM 메시지 전송 (0) | 2013.09.13 |
| Dialog (0) | 2013.02.22 |
| Fragment 기본 (0) | 2012.12.28 |
| 앱 연동 (0) | 2012.07.27 |
| Parcelable (0) | 2012.05.22 |
| Data Animation??? (0) | 2012.04.18 |
| Assets 폴더의 이미지 읽기 (0) | 2012.03.15 |
| JSON (0) | 2012.01.31 |