How do I set the input type for registration number. For example my university has specific format for registration number i.e. CIIT/SP17-mcs-044/Atk. I want CIIT/ATK is written already and Sp17-mcs-044 as a hint.
You can't define a random types of input type. You can only have one of these types as inputType.
If you want any custom behaviour, you might use TextWatcher and validate it
As #Tim has stated, the input type would be text over here and when user types in that EditText then check if the input is correct by using RegEx, and then show any message when the input is correct, for that you will need to add an OnTextChangedListener, about which you can learn more on official documentation.
Now, CIIT/ATK can be a TextView placed right before the EditText so it will be written already and will be uneditable. And yes, add that in final string after getting the input, like this:
finalInput = "CIIT/ATK" + input;
Related
I am wondering why Android doesn't support this.
To explain my problem. I am working on an accessibility feature for an Android app.
I have a TextView that displays a number value like 123456.
If I use TalkBack, it will always read just this number value.
What I want it to give this value a context so that TalkBack would read something like: "Number value 123456" I am not able to do that as contentDescription just overrides the text value and hint attribute is read after the value like: "123456 Number value".
Is there an alternative for this? Let me also say that the app is not using a separate TextView which would say "Number value" that TalkBack could read.
The solution I did was to use
var number = 123456
textView.contentDescription = "Number value ${number}"
I have a issue. My applications require formatting the EditText's value while typing. I.E., a number that needs to be formatted with decimal and thousands separators. Example, I input 123456789, this number must appear 123.456.789.
How to I do this issue ? Thank all.
Нou can implement TextWatcher to your editText. Here're useful links for you:
How to use the TextWatcher class in Android?
http://developer.android.com/reference/android/text/TextWatcher.html
There you need to upgrade your number.
Or you can create your own customEditText.
I'm trying to learn android, I'm having trouble with user input
I've used editText to get users to enter a date and email which is all fine, then i add a hint
for these fields like so:
android:hint="#+string/DD/MM/YY"
android:hint="#+string/example#example.co.uk"
and i get multiple marker errors in the generated files :/
I don't think you can use special characters in string names. Give it a meaningful name like support_email. You can find more information here.
Even if I set the input type to numberdecimal or number, I have to cast the number to get the number. Then what is the use of input type in EditText views.
e.g.
int a = Integer.valueOf(editText.getText().toString());
One more thing, why do I need to use toString() with almost every views to get Text? In java, we could just getText anything from controls.
You have to parse Text to Integer because it doesn't return int. It returns Editable formatted by input type. So if you set input type to numbers you get Editable which contains only numbers.
And you have to add toString() because EditText return Editables not Strings.
InputType is used for various purposes. For example, in a password field, it can hide the characters.
Here's the official description of every single property it can take:
https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
As for the second part of your question, EditText.getText() returns Editable
This defines a common interface for all text whose content and markup can be changed (as opposed to immutable text like Strings).
So you need to use toString() to get a string out of it.
For allow user only can input lower case alphabet and number, how can I setup my EditText in a xml file ?
Sorry, I did not provide clear information. I just want to filter or check user's input.
AFAIK, your question is complicated to do. better get a input from user. then you can convert that string to lowercase using toLowerCase().