I have a user reporting an error with my app. I have several EditText fields in my layout. I only want the user to be able to enter signed decimal numbers. However, I don't have the layout declare them to be number|numberSigned|numberDecimal because I have a custom TextWatcher attached to these fields which handles the input and makes sure it is correct. I do this because I want the minus key to act as a toggle.
Let's say, the field has "300" in it. If the user taps minus, my custom TextWatcher intercepts it and turns it into "-300" instead of "300-". If they tap minus again, it'll remove the existing minus and change it to "300".
This works just fine for just about everybody, but it doesn't work on the Kindle Fire. The decimal point and the minus key on the virtual keyboard are disabled, so they don't even have the option of tapping those keys and letting the custom text watcher do its work.
If I do declare the fields to be number|numberSigned|numberDecimal, then the fields won't let the user tap the minus key unless the cursor is in the left most position (i.e. before the 3 in 300).
How can I tell the Kindle Fire to make sure the decimal point and minus keys need to be active, but at the same time not restrict the user's allowed input before it reaches my custom TextWatcher... you know, like the way EVERY other Android device has been working for me? :)
The answer from #zapl:
theEditText.setRawInputType(Configuration.KEYBOARD_12KEY)
worked! Go find some other good answer of his and upvote him so that he can get proper credit for this answer. ;)
Related
Input action should happen like thisMobile Automation: I have a a scenario where i have to send keystrokes(inputs) from SoftKeyboard of an android device (like inputs from a real User). I tried with KeyEvent, SendKeys, androidkeycode, adb Shell input, Keys. Everything works fine, but i do not see any character pressed from a soft keyboard. Pls, help me to get solution for this.!!
The need: You need to simulate a press on the on-screen keyboard (using driver.tap())
The problem: Cannot get the Xpath or ID's of a on screen keyboard which puts us in a difficult situation.
Since i've struggled with this same problem in the past, i will advise you to create a function that calculate where each Key is located and press on it using the coordinates.
To be more clear:
Get the coordinates of lowest element you can find -> the keyboard itself is below it -> we can now know the height of the keyboard.
get the width of the screen
now, lets say you have a total of 4 rows(first row is q,w,e..) so we will divide the height by 4.
lets say you want a key from the first row which has 10 keys total, now dived the screen width by 10.
now you need to map each key to its location in a row. After that, call this function for each key you want to press.
I understand that it's ugly, and you will struggle with it a bit, but I don't know another solution to your problem.
In my application I have an EditText (Actually it's an implementation of MultiAutoCompleteTextView, but I don't think that matters) in which the user can enter a formula to be calculated, although generally they will want to just enter an integer.
What I would really like is for the keyboard to open with the numeric keyboard showing, but allow them to change to text if they want.
As standard of course it shows the letters and allwos them to change to numbers, which is OK, but 90% of the time they will want the numbers.
I tried doing:
operandEditText.setInputType(InputType.TYPE_CLASS_NUMBER|
InputType.TYPE_NUMBER_FLAG_SIGNED|InputType.TYPE_CLASS_TEXT);
But the result was a numeric keypad with letters written on the number keys (like a phone keypad), and it didn't write letters anyway.
I'm also aware that I could add a button, spinner or something that changed the input mode of the widget, but the aim of this is to make the interface easier to use, and I'm not sure adding another control will achieve that.
Is there a way to make it do what I want?
I'm trying to devise an input type for a field which will accept credit card numbers.
I had been using inputType="number" - but that won't let people with hardware keyboards hit the space bar.. when they do it jumps to another field in the activity.
I'd like to allow users to use a space in their numbers if they want, or, at least, make it so that if users with a hardware keyboard hit the space when I'm only allowing numbers it won't leave the credit card number EditText.
Ideally I'd be able to implement some interface and have my own custom inputType, but I'm not sure that's possible.
Is it possible to allow numbers and spaces, while showing the numbers soft keyboard?
The best choise is InputType.TYPE_CLASS_DATETIME
How about android:inputType="phone" in your layout xml file?
I don't have a definitive answer for you but here are some resources I picked up:
I found this clue to "catch" hard key presses: "To intercept hard keys, override InputMethodService.onKeyDown()". Read from bottom heading "Intercepting hard key events".
If you can't find a way to intercept and deal with the "space" key, I would suggest using a normal TextView and manually opening the number keyboard rather than the qwerty one (Go here for more info on general Input Reference). You can then validate key pressed from the hard keyboard.
Sorry I couldn't give you a more solid answer!
My application has a simple 'About' box.
It has a few clickable TextViews (email addresses, phone nos, addresses) all contained within a relative layout within a ScrollView (To accommodate low res screens).
The device I am testing with (Motorola Charm O.S ver 2.1 update 1) has a regular QWERTY keyboard. The problem I am facing is with the use of the arrow keys.
I want the cursor to move predictably from one clickable field to the next and this is where I need help. On the fields that don't need focus I have set the android:cursorVisible="false".I tried using the android:nextFocus* properties but still don't get the desired behavior.
The cursor gets stuck in the first field and overall the behavior is a bit unpredictable. Any ideas on how to get this done. Right now trapping the keys using code seems to be the only option.
TextView.setMovementMethod(LinkMovementMethod.getInstance())
The documentation is a little terse but it's basically what you are looking for.
Does anyone of you friendly coders know how to change the text on the return key of the android keyboard. I am catching the return event of an EditText element to start an action. So I would like to show the user, that he can start the action with that key. Some applications do that. E.g. they replace the key with a search symbol.
I am also wondering why apps always have an additional button aside the text field. Clearly, this takes away screen space. But it may be necessary for some purpose I am not aware off. The one problem I could imagine is task switching. After switching back, the user would have to call the keyboard before he could start the action. The other is a hardware keyboard, but anyone will assume that the return key will start the action.
R.G.
There are some ways to change the behaviour of the return button on your software keyboard. If you want to have the search Icon on your keyboard you have to add android:imeOptions="actionSearch" to your EditText View. There are some other actions that you can set for an overview over the available options have a look at the documentation of the TextView.
I would guess the reason that there are buttons next to many textfields to trigger the action is because users are used to it and would be a little bit at loss if the button is missing especially users with a hardware keyboard or if the software keyboard disappeared. One additional problem is that the return key is also used to create line breaks this means that if you want to have a multi line text field you cant use the return key to start an action.
If you want, you can hide the additional button beside the text area by adding the attribute
android:imeOptions="flagNoAccessoryAction" to your TextView or add it in code using
myTextView.setImeOptions(EditorInfo.IME_MASK_ACTION & EditorInfo.IME_FLAG_NO_ACCESSORY_ACTION);.
This is generally advised against, however, because of the user not being able to see what action will be performed when, say, the return key is pressed, or not being able to perform an action at all.
More info in this blog post: http://android-developers.blogspot.dk/2009/04/updating-applications-for-on-screen.html.