출처: http://www.androidpub.com/48864
EditText를 사용하며 글자수를 몇글자 이하만 저장될 수 있도록 하고 싶은데..
혹시 옵션으로 그런것을 설정 할 수 있는지 궁금합니다..
그게 아니면 글자 한글자씩 입력 될때마다 카운트를 해야하나요?;;
공지사항을 다 읽었음
혹시 옵션으로 그런것을 설정 할 수 있는지 궁금합니다..
그게 아니면 글자 한글자씩 입력 될때마다 카운트를 해야하나요?;;
공지사항을 다 읽었음
2010.04.26 18:13:55
inputfilter 사용하세요.////////////////////////////////////////////////////////////
출처; http://chaotic21c.egloos.com/10537099
ditText를 이용하여 텍스트를 입력 받을 때 특정한 길이만큼 제한을 줄 필요가 있다.
상위클래스인 TextView의 android:maxLength라는 xml attribute를 이용해도 되겠지만,
xml의 layout을 사용하지 않고 code상에서 구현을 할 수도 있다. 당연히.......ㅎㅎ
editor = new EditText(this); editor.setSingleLine(); int maxLength = 32; InputFilter[] filterArray = new InputFilter[1]; filterArray[0] = new InputFilter.LengthFilter(maxLength); editor.setFilters(filterArray); |
'구글과인터넷 > 안드로이드' 카테고리의 다른 글
안드로이드 리스트(또는 그룹리스트) 리스트 Add시 out of memory, 메모리릭 등 문제 관련 (0) | 2012.12.12 |
---|---|
안드로이드 editText에 처음에 포커스 안가게 하는방법 (0) | 2012.12.12 |
안드로이드 객체 복사 또는 배열복사 (자바 포함) (0) | 2012.12.12 |
TextView에는 아래와 같은
글자입력 길이 제한 속성을 제공하고 있네요...
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="5"
/>