Android layout.xml で選択した文字セット (例: A または B または C または D) のみを入力できるユーザーを制限する方法はありますか?
4 に答える
digits
属性を使用すると、渡された文字のみdigits
が EditText で許可されます。
android:digits="abc123"
はい、「数字」は誤解を招く名前です。文字や記号も受け入れます。
inputType
次の属性を使用できます。
<EditText android:id="@+id/edit_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" />
android:inputType
編集テキストの属性の可能な値は次のとおりです。none, text, textCapCharacters, textCapWords, textCapSentences, textAutoCorrect, textAutoComplete, textMultiLine, textImeMultiLine, textNoSuggestions, textUri, textEmailAddress, textEmailSubject, textShortMessage, textLongMessage, textPersonName, textPostalAddress, textPassword, textVisiblePassword, textWebEditText, textFilter, textPhonetic, textWebEmailAddress, textWebPassword, number, numberSigned, numberDecimal, numberPassword, phone, datetime, date, time
これandroid:digit
により、EditText に入力したい数字とアルファベットのみが許可されます。
<EditText
android:inputType="text"
android:digits="0123456789*qwertzuiopasdfghjklyxcvbnm,_,-"
android:hint="Only letters, digits, _ and - allowed"
/>
このように EditText フィールドを設定できます...
<EditText
android:inputType="text"
android:digits="THE SELECTED CHARACTERS THAT USERS ARE ALLOWED TO TYPE"
/>
ユーザーが android:digits に入力できる選択された文字 (A、B、C、および D) をリストすることで、ユーザーが入力できる文字を制限しています。これは、検索を通じて学んだ最も簡単な方法です。