Set dynamically digits for EditText - Android - android-edittext

I want to limit an EditText field to English characters and numbers only.
I can do this in the xml section as follows
android:digits = "..."
and dynamically as follows;
editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
However, only a keyboard with numbers appears, so there is no clickable letter but digits work correctly (I tested with copy paste).
Problem: Both the letter and the number should appear on the keyboard.
editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
editText.inputType = InputType.TYPE_CLASS_TEXT
I tried this but it loses its DigitsKeyListener feature.

Solution
editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
editText.setRawInputType(InputType.TYPE_CLASS_TEXT)

Related

Is there a way to use non-breaking spaces in a UILabel in a launch screen?

I would like to ensure that names in a multi-line copyright string on the launch screen do not get split by line breaks on different devices. Inside a view controller with a UILabel outlet textLabel, the escape sequence "\u{00a0}" works programmatically:
textLabel.text = "Lots of text before... Firstname\u{00a0}Lastname... and after."
It displays the string with the escape sequence replaced by a space and the words either side always appear on the same line.
However, I can't get it work by putting it in as the value in a UILabel in Interface Builder - either in LaunchScreen or any other View Controller. It just displays the string with the codes left as typed. I've tried all the various combinations of \u, \U, \\u, \\U, \x+, etc. suggested in several SO questions to no avail. I think intervening in the display of the launch screen programmatically is impossible.
Have I missed something?
Don't use \u{00a0} in the text you enter into the storyboard. Enter an actual non-breaking space. The easiest way is to type ⌥-space (option-space).
If you ever need to enter any other special characters, another option is to use the standard Character Viewer. Select Emoji & Symbols from the Edit menu to bring up the Character Viewer. Then find the desired character that you wish to put in a label. You can do this in Swift code as well instead of typing cryptic Unicode escape sequences into your strings.

UILabel text wrong new line when has special character

Details of the issue :
When display text inside UILabel and almost the text fill complete line, if you add one more character with spacial character such as "ً" (check number 1) , it cuts first letter of text and put it in line alone(check number 2) and the rest of text in other line (check number 3)
Please note that the issue happening in the Facebook app and iOS note app
Try setting the linebreak mode to word wrap.
This may help.
Another option, try using textview instead of label.

Can i replace the period in decimal pad with a comma in Swift 2 iPhone app?

Or maybe add a comma on the number pad without creating a custom keyboard.
I tried changing NSLocale to to another country but that didn't work. I have a function that separates multiple numbers from textFiled to evaluate them separately separated by commas but the keyboards do not contain a comma and i would rather not use the numbers and punctuation keyboard for this. Any help is appreciated. Using Xcode 7.2.
You can't change the keys on any of the built-in keyboards.
You can create your own keyboard view with the inputs you want (numbers, the comma, backspace) and set it as the inputView of your text field. The system will display your keyboard view instead of a standard keyboard when your text field becomes first responder.
Or you can just create, say, a toolbar with a comma button on it, and set the toolbar as your text field's inputAccessoryView, and let the text field use the standard decimal pad for numbers and backspace. The system will display your input accessory view above the standard keyboard when your text field becomes first responder.
Read “Input Views and Input Accessory Views” in the Text Programming Guide for iOS.

How to Start in Numeric Side of Keypad in Objective C

I have some alphanumeric content that gets entered routinely and is mostly numbers, so I'm wondering if there's a way to start in the numeric side of the keyboard but still have the option to switch to the alphabetic keyboard in Objective-C for iPhone development specifically. I've found plenty of info on using the numeric keyboard but I'd like to start there but still be able to enter letters if that's possible.
Thanks.
Set the keyboardType property to UIKeyboardTypeNumbersAndPunctuation.
This will default the iPhone's keyboard to show numbers and punctuation but the little "ABC" key will be in the bottom left allowing the user to switch back to the letters (and then back to numbers and punctuation).
Try this:
[Objective - C]
[self.myTextField setKeyboardType: UIKeyboardTypeNumbersAndPunctuation];
[Swift]
self.myTextField.keyboardType = .NumbersAndPunctuation
// You can also set this property from the storyboard.

How to keep the last character always visible in an input field on mobile safari?

I've a mobile web app and in it I've an input field type text.
I'm assigning it's value as
function setVal(str){
var item = $('#textField'),
string = item.val()+str;
item.val(string);
}
As the value is set programmaticaly without focusing on the field and typing on a keyboard, as the string gets longer than the width of the text-field, I can no longer see the new character additions as the text-field masks it.
You can see in the image above, the right most letter is 'K' (after j) but only part of it is visible.
How do I make sure that if the length of the string is more than the width of the text-field, the extra length goes left ward and the last letter is visible on the screen all the time?
Not exatly what you're looking for, but you can scroll left the text inside equally to the length of the input text, so the last character can always be visible.
var el = document.getElementById('textField');
el.focus();
el.scrollLeft = el.scrollWidth;
<input id="textField"></input>

Resources