Phone number format for EditText - android

I am using library input-mask-android to format the text as user is typing.
I have an array of phone number masks. By default, the very first mask in the array is selected. The user can choose a different mask using the Spinner. But when the user selects a mask using the Spinner, it does not work as he would like.
Suppose the array of masks contains two masks: ["+12 - ###", "+34 - ###"]. If the user selects the second mask, then the following will appear when typing into the EditText:
Entered 5 will:
+34-512.
That is, after entering it will automatically put the key characters of the previous mask.
My code in Kotlin:
val listener: MaskedTextChangedListener = installOn(
etPhoneNumber!!,
maskT,
affineFormats, AffinityCalculationStrategy.PREFIX,
object : ValueListener {
override fun onTextChanged(
maskFilled: Boolean,
extractedValue: String,
formattedValue: String
) {
logValueListener(maskFilled, extractedValue, formattedValue)
Log.e("CHANGE FORMAT:", affineFormats.toString())
}
}
)
maskT - is the selected mask
affineFormats - dynamic array where the last mask is stored.
Any suggestions would be greatly appreciated.

input-mask-android library author here.
The installOn method won't suit your needs. You've got to manually initialise a MaskedTextChangedListener, then call an addTextChangedListener method on your EditText. On mask select, you've got to make sure the previous listener is removed (by calling a removeTextChangedListener on your EditText).
The installOn method does not consider there could be other TextWatcher instances attached to your EditText. Thus, all of those installed listeners are trying to take over the text, adding their own "+12" and "+34" prefixes simultaneously.

Related

AutocompleteTextView text clear if entered value is not found from list

I have a dynamic arraylist that contains String values. I want to match one of its values with AutocompleteText whatever the user has typed/entered. In case the value is not matching with any of the Arraylist values I would like to clear Autocomplete Text.
Couple of Ways I have tried.
Match the typed or user selected value from autocomplete text with list directly without any loop using "contains" method. Didn't achieve the expected result.
Store the values in String[] array from list and loop through it and match it with user input/selection from Autocompletetext. Didn't achieve the result this way too.
Please provide any ideas on how to clear text from autocompletetextview if value is not found?
You did not specify any language that's why i will answer in kotlin
Override onKeyDown method and let's say you will check when enter pressed check if given keycode value equals to KeyEvent.KEYCODE_ENTER
In if block get your text and use an algorithm like below
val arr = intArrayOf(1,2,3) if (textFromTextView !in arr) it means your typed text not in your array and if this condition is true
use autoCompleteTextView.replaceText("") and i hope it will work for you.I never tried but i searched for you.

Android accessibility announcement reads textview differently than what I expected

For example, after setting Text in TextView to '347309', TalkBack should read "three, four, seven, three, zero(or o), nine."
But it announced "three hundred forty- seven thousand thirty nine."
In another case,
I set text 'API' (Application Programming Interface).
I want TalkBack to announce "A-P-I," but it announces "eipi" or "eipaɪ."
How do I get TalkBack to announce correctly?
Click here to check code. You need to take char array of that string and make separate each char with appending space and set that string as a content description to your view.
Here's the code :
Var str="347309"
textView.setContentDescription =getCharFromText(str)
fun getCharFromText(str:String):String
{
Var sb= StringBuilder()
foreach(c in str.charArray())
{
sb.append("")
sb.append(c).append(" ")
}
return sb.tostring()
}
Talkback has built-in functionality to adjust how text is read. By swiping up or down the screen, the user is able to go from default to reading out the text letter-by-letter if they need to.
It's preferable to allow the user to control this via existing controls, rather than force this choice programmatically.

Android, Xamarin, EditTexts: Disable the user from deleting the first letters

I want the user to type in his or her Facebook account-link (don't have a better solution atm).
Now, when the user clicks the edittext it is supposed to say : "www.facebook.com/". Now the cursor is supposed to be at the END of the edittext (after the "/") and the user is not supposed to delete the first letters so that the "www.facebook.com/" stays exactly where it is. This will have the user to ONLY type in his or her facebook name and therefore connect the profile.
Is there a way of doing this?
Thank you :)
You can do that by using the event "TextChanged" and in your code validate if the size is big than your string, like that:
if (((EditText)sender).Text.Length >= 17)
{
((EditText)sender).Text = e.NewTextValue;
}
else
{
((EditText)sender).Text = "www.facebook.com/";
}
So if the value is bigger than your string you will replace that for the value, if not you just set the value with your string

How to set string on Spinner Prompt programmatically?

How to set the string values on spinner prompt?
The process how I am doing is:
I am able to retrieve the json data(it has only one single value), so I am getting the single text with the help of String.
Later, I am trying to set the string value in Spinner prompt
SP_gender is called as Spinner here. In String gender1, I have texts called as "male"
String gender1 = i.getStringExtra("bundle_CusGender");
SP_gender.setPrompt(gender1);
System.out.println("Check bundle_CusGender = : " + gender1);
When I try to print this, I am getting a value as male
System.out: Check bundle_CusGender = : male
How should I set the single text in spinner Android?
Firstly the setPrompt() methods documentation states:
Sets the prompt to display when the dialog is shown.
Which is pretty vague but internally it calls the setPromptText() method which sets the description on the popup and has the following documentation.
Set hint text to be displayed to the user. This should provide
a description of the choice being made.
So if I am understanding your question correctly you want to set the spinners selected item. You should be using either setSelection(int) or setSelection(int, boolean)
For those to work you would need to give your spinner an adapter if you haven't already. If you don't know how you should check out this answer which explains in more detail.

Android KeyCodes for combination of letters

I am implementing a custom input method (softkeyboard ) for android...Its a gesture detection keyboard,so I will capture the direction the users swipes and the code for that.In doing so,I have some combination of letters like "Th" and "Ch" for which I would need the int value.The char values can be easily converted ,but how to get int values for combination of characters...Please suggest.
I need getCharacter(code) to return an int.
Only by successive calls to getCharacter().. take a step back and see that this method is not the best point to be implementing what youre trying to do. The handler that returns the multiple chars (strings) should implement getCharacter() successively on every character in the string. If I am understanding the problem correctly.

Categories

Resources