TextInputEditText to show numeric keyboard but also allow / - android

I've been trying to adapt my TextInputEditText which shows a numeric keyboard currently (it has android:inputType="numberDecimal" in the xml) to allow input of a / character (by clicking a button in the ui that appends a / to the EditText).
What I want to achieve: A numeric keyboard & allowed to enter / in the EditText
Everything I have tried either doesn't show a numeric keyboard or doesn't allow me to add the / to the EditText.
Things I've tried:
Adding android:digits="0123456789./" to the xml
Result: It's still a numeric input and won't let me .append("/")
Setting android:inputType="text" in the xml and the below in the activity's onCreate()
input.setFilters(new InputFilter[] {(src, start, end, dst, dstart, dend) -> {
if(src.toString().matches("[0123456789./]+")){
return src;
}
return "";
}});
Result: I don't get a numeric keyboard (although I can only enter the characters I need which is good)
android:inputType="text" with android:digits="0123456789./" as this seems to be suggested quite a few times on various SO answers (and I assume must have worked at some point).
Result: a non-numeric keyboard (i.e. regular text input keyboard)

Removing android:inputType and android:digits from the xml and also adding the below to the activity's onCreate() seems to do the trick.
input.setKeyListener(DigitsKeyListener.getInstance("0123456789./"));
However it's not completely clear to me that this should or will always work - see note below from the docs on DigitsKeyListener...
As for all implementations of KeyListener, this class is only concerned with hardware keyboards. Software input methods have no obligation to trigger the methods in this class.
Source: https://developer.android.com/reference/android/text/method/DigitsKeyListener

Related

Show comma instead of dot - Keyboard

Is there a way to get a comma for edittext instead of dot. My Keyboard is german, device is samsung.
looking for solution via XML not extra listeners.
So far i have tried
1.
android:digits="0123456789,"
android:inputType="number"
android:digits="0123456789,"
android:inputType="numberDecimal"
android:inputType="numberDecimal"
nothing seems to work, and I still get dot. I have gone through other similar questions but they suggest managing it by adding listener to edittexts. I have a lot of editText and it will be much additional/unnecessary work. There should be an XML simple solution to this.
Also tried
val input = EditText(requireContext())
input.keyListener = DigitsKeyListener.getInstance("0123456789.,")
EditText input = new EditText(THE_CONTEXT);
input.setKeyListener(DigitsKeyListener.getInstance("0123456789,"));

Android: EditText not allow special characters with Next softkey

I have an EditText which is required to accept only alphanumeric characters. No any special ones allowed (such as: Á, Â...)
I added some properties:
android:inputType="text|textCapCharacters|textFilter"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
android:imeOptions="flagNavigateNext"
android:nextFocusLeft="#+id/txtYearOfBirth"
android:nextFocusUp="#+id/txtYearOfBirth"
android:nextFocusRight="#+id/txtFirstName"
android:nextFocusDown="#+id/txtFirstName"
It worked fine for no special characters but the soft key Next is replaced by Enter:
How can I keep the Next button instead?
Thank you very much for any help.
Use these following properties of EditText and check
android:maxLines="1"
android:singleLine="true"

Soft keyboard with comma instead of dot for decimal separator in android

I have been reading some threads about this problem and some are not answered and others (from 2011) explain how this was a known bug.
Has this been solved? Is it possible right now to show soft keyboard with culture information? I would like to show a decimal keyboard showing a "," instead of a "dot" for the decimal separator.
You can use the following workaround to also include comma as a valid input:-
Through XML:
<EditText
android:inputType="number"
android:digits="0123456789.," />
Programmatically:
EditText input = new EditText(THE_CONTEXT);
input.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));
In this way Android system will show the numbers' keyboard and allow the input of comma. Hope it helps :)
It is not possible to not show the '.' in the soft keyboard without creating your own one.
The solution than I found is:
<EditText
android:inputType="numberDecimal"
android:digits="0123456789," />
This way when you press the '.' in the soft keyboard nothing happens; only numbers and comma are allowed
I solved this by extending NumberKeyListener to accept ',' and '.',
and overrode:
#Override
public int getInputType() {
return InputType.TYPE_CLASS_NUMBER
| InputType.TYPE_NUMBER_FLAG_DECIMAL
| InputType.TYPE_NUMBER_FLAG_SIGNED;
}
Furthermore I set a TextWatcher on the EditText, which replaced all '.' with ',' in afterTextChanged().
But I could not manage to show a comma on the softkeyboard.
In android namespace you can use:
android:inputType="numberDecimal"
Which enables you to input the "."

Android How to show numeric softkeyboard with EditText of InputType="text"

I need allow to user input numeric information in a EditText, but the output needs to be formatted like "##.###,##" (# in [0..9]). The formatting I was made in a TextWatcher... this is good, the TextWatcher does the job... bute, when user selects the EditText, as it marked as text, the AlphaKeyboard is shown, if I select the EditText as numeric the keyboard I need is shown and the TextWatcher stop working.
put the following in your xml at the required edittext
<EditText android:inputType="number" ... />
refer to
How do I show the number keyboard on an EditText in android?
You need to change edittext entry like this.
<EditText android:inputType="phone" android:numeric="decimal"></EditText>
Use this code to show soft keypad.
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(v.getApplicationWindowToken(), 1);
As you are doing formatting in TextWatcher (##,####....) i.e. you are adding "," in EditText and you have made the EditText as numeric. If its numeric then "," char is invalid. Thus its not allowing TextWatcher to update the formatted text that contains ',".
You have 3 options to deal with this problem :
Make the EditText as normal instead of numeric. In TextWatcher look out for any other invalid chars other than 0-9. You can show IME for Mumber keypad when the focus is on the EditText.
Use Mask for EditText.
Let it be numeric. Trap FocusGain & FocusLost for the EditText. In focusGain, remove the formatting & set the inputType to Numeric. & In focusLost, first make the input type to Normal and then update the entered value to formmated value. You can set the input type to normal at runtime using setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL); & for numeric use : setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
I believe 1st option will be best to handle and manage out.

Android: inputType none and physical keyboard

I have a problem with TextEdit,
if I do editText.setInputType(InputType.TYPE_NONE); the user is not able to type anything.
Anyway, if there is a physical keyboard attached, then the user can type by using it (of course the soft keyboard doesn't work).
Is there any way to fully disable editing on a EditText?
PS: I need to do that programmatically at runtime
Try
android:editable="false"
in xml layout file
android:editable="false" is deprecated ,prefer not to use it.
Another solution to this that I used is given below
first_password_EditTextBox = (EditText) findViewById(R.id.editText1);
first_password_EditTextBox.setEnabled(false);

Categories

Resources