I am looking to implement both phone pad and keypad in Android.As, per my requirement when the EditText is selected a default phone pad should be shown. But the user must be able to input alphabets also. Please suggest me a way to implement this.
<EditText
android:id="#+id/editTextref1"
android:layout_width="210dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:ellipsize="start"
android:hint="#string/custom1"
android:imeOptions="actionNext|actionDone"
android:inputType="text"
android:nextFocusDown="#+id/editTextref2"
android:shadowDy="10"
android:textColor="#383838"
android:textSize="14sp"
android:textStyle="bold"
android:maxLength="15"
android:typeface="serif" />
I would like to make an assumption that it's impossible to do that in a simple and elegant way. The problem is that you input type is InputType.TYPE_CLASS_TEXT and it cannot be changed to InputType.TYPE_CLASS_NUMBER because you need to input letters as well.
The problem is that input method checks the type of input and gives you the appropriate keyboard with numbers or alphabet depending on the type of the field input type. If you ask input method to give you number keyboard and you have your EditText in focus, you cannot force the input method to switch to alphabet keyboard in your code. I may be wrong but this is what I think.
The question is whether you can ask any third party input method to give you different keyboard while editing text - I think you cannot do this in your code. Input method will give you numbers or alphabet depending on your EditText but you cannot switch them dynamically because input method is not aware of your design issues. The only way you can do this is to make your own input method that allows you to switch numeric and alphabet keyboards dynamically.
Related
In my Android application, I have a field where 95% off the time it's only numbers.
So I set the inputtype of my edittext as "number"
But I have some case where the user must enter char in the field Ex : AF1233636
In my case using the standard alpha numeric keyboard is a bad option because users must wear gloves.
So I found the inputype "phone" where there is number and chars but only numbers are working.
I cannot get char inside my fields only numbers
<EditText
android:id="#+id/fld_tag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:clickable="true"
android:cursorVisible="false"
android:inputType="phone"
android:digits="0123456789abcdefghijklmnopqrstuvwxyz"
android:focusable="true"
android:maxLength="10"
android:textStyle="bold" />
So when the user stay push on a number I want the char appear as it was working on old phone to write text.
Any idea ?
Check out this tutorial for creating a custom IME https://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615 ... create something similar to this except with t9 functionality. Those letters underneath the numbers are just for visualizing when typing in a phone style app.
Is it possible to prevent a user from changing input method/keyboards?
I know it's not allowed by default but maybe with some security/IT device administration feature it is possible?
I've been looking around but couldn't find a definitive answer.
If you want to add some constraint that, this specific EdiText wont must raise a special type of keyboard (number pad / text) to type in. Add the following parameter in the EditText block layout/xyz.xml.
android:inputType=""//your specific type gies here e.g "number" "textUri" ...
details
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="142dp"
android:layout_marginTop="145dp"
android:ems="10" android:inputType="number">
you can also change it from the properties view by selecting appropriate EditText.
As far as the search I performed suggests - there is no such way to prevent users from changing input method.
I want to allow only negative numeric and decimal input with the nice numeric keypad that shows all the numbers in a 3x3 keypad. This keypad has a negative button, but it doesn't do anything, and I can't figure out how to activate it. The following is what I have, but it only allows numeric input:
<EditText
android:id="#+id/expense_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/FieldNumeric"
android:text="0.00"/>
I've seen several answers already that say to add
android:inputType="numberSigned"
or to use
TYPE_NUMBER_FLAG_SIGNED
among other suggestions. The problem with these answers is they lose the nice 3x3 numeric keypad and bring in the alphabetic keyboard.
Any suggestions would be awesome.
Thanks,
Devin
This worked for android 4.2.2 (Jellybean):
android:inputType="numberSigned|numberDecimal"
Let's say I have an EditText and I want to restrict it to 0-9 and A-F (inclusive), for hex input. Is there a way I can do that? I tried looking at InputFilters and I'm not sure that's the right way. Has anyone achieved this?
Set the input type to number and digits to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
In an xml file it would look like this:
<EditText
android:id="#+id/hexedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="number"
/>
You can experiment with different inputTypes to see which soft keyboard layout they bring up.
Is there a way in android to invoke a numeric only keypad, i.e. a virtual keypad that contains only the numbers 0 to 9 and a "." sign?
Try doing android:inputType="phone" ?
Basically, you need what Peter Boughton said.
More generally, if you need to invoke different type of keyboard, depending on the input you expect on your EditText component, you should use the IMF (Input Media Framework) and different IMEs (Input Media Editors).
You can customize not only the input symbols, but also the layout of the keyboard in your application, auto-completion and other options.
You may want to read this post in the Android Developers Blog:
Updating Applications for On-screen Input Methods
If you're talking about restricting input to 0-9 + "." for an EditText box, I use the android:numeric="decimal" attribute in the layout XML.
<EditText android:numeric="decimal" />
If you're working with dynamically generated EditText views, the relevant method to call on it is
setKeyListener()
Make sure you only have:
<EditText android:numeric="decimal" />
and not both:
<EditText android:numeric="decimal"
android:digits="0123456789." />
The latter, ie using both numeric and digits was not working for me. However, using only numeric works.
<EditText android:numeric="decimal" />
only does not affect keypad to convert into decimal.
Instead, use:
<EditText android:inputType="phone" android:numeric="decimal"></EditText>
This will show the numeric keypad only.