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) をリストすることで、ユーザーが入力できる文字を制限しています。これは、検索を通じて学んだ最も簡単な方法です。