Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a EditText to the input of only hexadecimal numbers?

I would put in this code a control on EditText so that it only accepts hexadecimal numbers. How do I go about doing this?

bin = (EditText)findViewById(R.id.editText02);
hex = (EditText)findViewById(R.id.editText3);
dec = (EditText)findViewById(R.id.editText1);
oct = (EditText)findViewById(R.id.editText04);
like image 834
whiteTIGER Avatar asked May 18 '12 07:05

whiteTIGER


1 Answers

In your android layout XML file add the following attributes to EditText:

<EditText
android:digits="0123456789ABCDEF"
android:inputType="textCapCharacters"
/>

The first attribute allows only input with these numerals. Any other input is rejected and not displayed. The second attribute capitalizes characters.

credit goes to this blog post: http://mobile.antonio081014.com/2012/04/how-to-let-input-of-edittext-only-be.html

like image 126
Muhammad Annaqeeb Avatar answered Oct 23 '22 05:10

Muhammad Annaqeeb