android에서 edittext에 숫자 값만 설정하는 방법은 무엇입니까?
나는이이 edittext
값을 삽입 할 정수하는 난 단지합니다. 누군가 내가 사용해야 할 재산을 말해 줄 수 있습니까?
android:inputType="number"
xml 특성을 추측 합니다.
예를 들면 다음과 같습니다.
<EditText
android:id="@+id/myNumber"
android:digits="0123456789."
android:inputType="numberDecimal"
/>
코드에서 할 수있는 일
ed_ins.setInputType(InputType.TYPE_CLASS_NUMBER);
숫자 만 입력 사용을 위해 android:inputType="numberPassword"
함께 editText.setTransformationMethod(null);
수의 자동 숨기기를 제거합니다.
또는
android:inputType="phone"
숫자 입력 만하면이 두 가지 방법 이보다 좋습니다 android:inputType="number"
. inputType으로 "number"를 언급 할 경우 키보드로 문자를 전환하고 다른 특수 문자를 입력 할 수 있습니다. 키보드에 숫자 만 표시되므로 "numberPassword"inputType에는 이러한 문제가 없습니다. 키보드를 사용하여 문자로 전환 할 수 없으므로 "phone"inputType도 작동합니다. 그러나 +, /, N 등과 같은 특수 문자를 계속 입력 할 수 있습니다.
로이드 : inputType = "numberPassword" 와 editText.setTransformationMethod (NULL);
inputType = "phone"
inputType = "number"
android:inputType="numberDecimal"
<EditText
android:id="@+id/age"
android:numeric="integer"
/>
아래를 사용하면 문제를 더 잘 해결할 수 있습니다.
xml에서 :
<EditText
android:id="@+id/age"
android:inputType="numberDecimal|numberSigned" />
또는 // etfield.addtextchangelistener 내부의 활동
private String blockCharacterSet="+(/)N,*;#";//declare globally
try {
for (int i = 0; i < s.length(); i++) {
if (blockCharacterSet.contains(s.charAt(i) + "")) {
String corrected_settempvalue = arrivalsettemp.substring(0, arrivalsettemp.length() - 1);
et_ArrivalSetTemp.setText(corrected_settempvalue);
if (corrected_settempvalue.length() != 0)
et_ArrivalSetTemp.setSelection(corrected_settempvalue.length());
}
}
} catch (Exception d) {
d.printStackTrace();
}
If anyone want to use only number from 0 to 9 with imeOptions
enable then use below line in your EditText
android:inputType="number|none"
This will only allow number and if you click on done/next button of keyboard your focus will move to next field.
You can use it in XML
<EditText
android:id="@+id/myNumber"
android:digits="123"
android:inputType="number"
/>
or,
android:inputType="numberPassword" along with editText.setTransformationMethod(null); to remove auto-hiding of the number.
or,
android:inputType="phone"
Programmatically you can use
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
I need to catch pressing Enter on a keyboard with TextWatcher. But I found out that all numeric keyboards android:inputType="number" or "numberDecimal" or "numberPassword" e.t.c. don't allow me to catch Enter when user press it.
I tried android:digits="0123456789\n"
and all numeric keyboards started to work with Enter and TextWatcher.
So my way is:
android:digits="0123456789\n"
android:inputType="numberPassword"
plus editText.setTransformationMethod(null)
Thanks to barmaley and abhiank.
the simplest for me
android:numeric="integer"
이 또한 더 많은 사용자 정의
android:digits="0123456789"
참고 URL : https://stackoverflow.com/questions/4645119/how-to-set-only-numeric-value-for-edittext-in-android
'IT story' 카테고리의 다른 글
한 자리 숫자 앞에 0을 추가하는 PHP, 즉석에서 (0) | 2020.05.10 |
---|---|
PHP-컬 디버깅 (0) | 2020.05.10 |
Android에서 파일 시스템 만 읽기 (0) | 2020.05.10 |
'#'링크 클릭이 페이지 상단으로 이동하지 못하게하는 방법은 무엇입니까? (0) | 2020.05.10 |
안드로이드에서 라디오 그룹의 선택된 인덱스를 얻는 방법 (0) | 2020.05.10 |