I have an EditText where I only allow the characters $0123456789.
Everything is working well except when I press the number 4 (on virtual or hardware keyboard) it prints a dollar sign ($).
Why is it doing this?
Here is the XML for my EditText:
<EditText
android:id="#+id/amount_text"
style="#style/textbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"
android:cursorVisible="false"
android:digits="$0123456789."
android:gravity="left|center_vertical"
android:hint="#string/amount_hint"
android:inputType="textPhonetic|numberDecimal" />
Secondary question:
mAmountTxt.setKeyListener(DigitsKeyListener.getInstance(false, true));
This achieves what I want (sans $). However, it changes the virtual keyboard to one I don't want. I want the phone keyboard with the big number buttons.
First, I'm 100% sure that it doesn't relate directly to your EditText xml. I have tried your xml in Emu 2.1, Emu 4.0, Emu 4.1 and Real Phone 4.0, and it worked well in each.
Other possible causes:
It might be the emulator - they are sometimes buggy. Can you try to make a new instance of the emulator and test it? Or, try restarting adb?
It might be something programmatic. Do you do any replacing or something like that?
I'm not sure what this does: style="#style/textbox"
Second, to make keyboard layout look like a phone, use this instead of setKeyListener
mAmountTxt.setInputType(InputType.TYPE_CLASS_PHONE);
You wrote:
I want the phone keyboard with the big number buttons.
Set inputType to:
android:inputType="phone"
instead of:
android:inputType="textPhonetic|numberDecimal"
Related
I created an EditText that only allows numbers as an input. It's a very simple EditText with nothing special:
<EditText
android:id="#+id/editTextAmount"
android:layout_marginTop="10dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:inputType="text"
android:digits="0123456789"
/>
I tried it on a few devices and it's working as expected, I can enter only numbers. The issue arise when using a Samsung Galaxy Note S10+ (with a Samsung keyboard, I think the issue comes from there). With that device when I focus the EditText the keyboard opens (with only number visible) but when I type something in the field nothing happens. I can press any key from the keyboard (enter key, numbers, ...) nothing changes.
I tried to change the input type programmatically in the activity, I tried to fiddle with the inputType (numberDecimal, numberSigned, both, ...) in any case it is simply not working. The interesting thing is that if I change the inputType to "text" and remove the digits restriction then it is working perfectly.
My question is: How can I limit the EditText input to numbers with a Samsung Galaxy Note S10+?
EDIT: Just to make it perfectly clear, I am asking this for a specific device! I already tried:
android:inputType="number"
And
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
And
any variation of those (numberDecimal, numberSigned, ...)
in Java class set input type like this
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
or if you want to do that from layout then set
android:inputType="number"
It seems to work well with this configuration:
android:digits="0123456789"
android:inputType="phone"
That's a good enough workaround for me.
I seem to have quite a specific problem. I have two tablets, one runs on Android 6.0.1, the other on 5.1.1.
I have an activity and a fragment (the fragment is located on an activity). Each has an EditText element with the following layout:
<EditText
android:id="#+id/etInputForm_1_1"
android:layout_width="250dp"
android:layout_height="30dp"
android:layout_below="#id/tvDescription_1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:cursorVisible="true"
android:imeOptions="actionNext"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:textColor="#color/Black"
android:textSize="15sp"/>
The problem is, if I test it on the device with Android 6.0.1, everything seems to be ok, I can input text wherever I want to, however on the device with 5.1.1, the EditText in the fragment always seems to be empty no matter how many letters I type (the EditText in the activity still works fine).
But the logs still show that the text IS there (however we can't see it).
Anyone had similar problem and a solution to this?
I had a similar issue where the edit text hint wouldn't go away (representing text was in the field) and no text would show up when I was typing but my logs showed text was indeed in the field. I also had an issue where my spinners would not show the selected option
I solved it by enabling hardware acceleration for my application. Since it is enabled by default (I believe) I removed this line from my <application></application> section of my manifest file: android:hardwareAccelerated="false"
My issue resolved after removing following line from edit text.
android:textAllCaps="true"
The problem was resolved by using android.app.Fragment instead of android.support.v4.app.Fragment. Seems that the support fragment class is buggy when using on tablets with Android 5.1.1.
I'm developing an Android application in which I have an EditText control.
I've set the gravity to right, in order to type in Persian.
But when I try to select a text (which is in Persian), the select pointers won't appear.
It works almost fine when the gravity is not set. Also it works fine in other devices like Samsung. But it doesn't work on HTC devices (HTC One xl in my case).
This is my EditText xml
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/txtShare"
android:layout_weight="1"
android:enabled="true"
android:inputType="text|textMultiLine"
android:hint="#string/typeHere"
android:gravity="right"/>
Does anyone know how to fix this?
Edit 1
Also the cursor is always at the beginning of the lines, no matter where I tap in the text.
Edit 2
I'm almost sure that if I can solve the problem in Edit 1, the first problem will be solved along with it. Cause wherever I click in text, the cursor would remain in the beginning of the line
Try adding following attribute to your EditText
android:ellipsize="end"
If you are using right-to-left text you should use the textDirection property for correct support. Gravity only aligns text, so text you enter would still be left-to-right.
The cursor selection is handled in the onTouchEvent method.
I don't have any HTC device, so just an idea.
Maybe you can try to find the problem from the onTouchEvent method.
I have a edit text, whose input type is number.
in emulator its working fine i.e, showing the num-pad as soft keypad.
but in the device its showing alphabets keyboard why?
<EditText android:layout_width="110dp"
android:layout_height="30dp" android:id="#+id/phone"
android:layout_alignParentRight="true" android:background="#drawable/edit_text_bg"
android:inputType="number" android:maxLength="10"
android:paddingLeft="4dp" android:textColor="#1b0a00"
android:layout_marginRight="8dp"/>
Thanks in advance....!
So from what i've observed setting the inputType to phone should solve the problem . But try a different device to check if ur code works by giving input as number before moving to this option .
I think you must change inputType
FROM :
android:inputType="number"
TO:
android:inputType="phone"
When you give the InputType as number there is a completely new keyboard that gets loaded very different to what you will get by pressing the corner button on your normal keyboard to get numbers . Only certain phones/android versions(i think 2.2+) have this separate keyboard . For the ones that dont have this , The normal keyboard is shown and manual switching has to be done .
It could be that the device you're testing has some sort of custom keyboard enabled by default that doesn't support a number pad. Try changing the keyboard settings to the standard keyboard on the device and see if it works.
developing an android app here using API 7. I have an EditText that we use to filter down the list beneath it, so we set the inputType to textFilter so Android wouldn't suggest words or auto-complete.
However, when the user types a character they see the popup box in which they're doing the search shrink. It is clearly getting smaller to make room for the suggestion bar, even though the suggestion bar doesn't actually show.
Using textNoSuggestions instead appears to have the same result. Here is the snippet for the input box:
<EditText
android:id="#+id/search_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:inputType="textFilter"
android:background="#null"/>
Has anyone experienced and overcome this behavior? It doesn't repro on SenseUI, but probably because SenseUI floats the suggestion bar instead of claiming screen real estate for it.
Try textNoSuggestions. I'm not sure what textFilter does, I was hoping to use it to limit input to 0-9 and A-F for a hex keyboard, but found this instead.
The only thing that works consistently in my experience is textVisiblePassword. This both prevents autocorrection and doesn't change the size of the field. Very annoying.