I have a screen with prefilled EditText. Whole it's text is selected via
editText.setSelection(0, editText.getText().length());
I do that so users are able to rewrite that text immediately, but when I hit some key it doesn't write it. It just deletes the selected text and then allows me to write. Is this an expected behaviour please?
editText.setSelection(editText.length());
will set the cursor to the end but it is to be noted there are two types of text that are set.
There is a hint (this will be wiped as soon as you press on it and it just sits in the background as a prompt to the user)
editText.setHint("Hey");
And then there is the text (this wont be wiped as soon as you press it)
editText.setText("Hey");
Related
I would love to add this elegant verification code screen to my app but I'm completely lost in how to do it
should I implement each box as a TextInputEditText ?
how can I make the cursor move from one box to the next one while typing ?
ps : I'm using kotlin
I would make those boxes as a TextViews (not EditText) - you don't want to have a soft keyboard opened and the user will be only using buttons below in order to enter verification code.
When the user presses number below - show it in the next available TextView, when every TextView is filled with number - verify whole code. The same should work backspace button - clearing previous filled TextView.
You might want to make TextView to be highlight when it is going to be filled with the next number press, you can do this with a state-list background.
I have a very weird, but consistent bug in my app with any standard Android keyboard that supports word predictions.
What I’m doing is that I call InputMethodManager.restartInput() after I evaluated the input of an EditText to show a different IME label (I check the current text with a TextWatcher and the set the label to ”Close” when the text is empty and to “Send” when it's not). Without calling restartInput() the IME label change is not taken over until the connection is otherwise renewed, e.g. by closing and reopening the keyboard again.
Now when I manually enter characters through the keyboard everything is fine as expected, labels are changed, key strokes are accepted, all good, but if I click on one of the predictions on some keyboard to paste the word, the second click on the prediction is lost (i.e. the word that should be pasted after I called restartInput()).
"Lost" means different things for different keyboards, SwiftKey for example keeps the first word underlined and then replaces that with the second word on click, while Google's keyboard just keeps the first word, ignores the second word completely and then continues with any next word.
This video shows the issue: https://puu.sh/v0WUo/8f9b3571ed.mp4
I click on “Test and the”, but the EditText only receives “Test the".
Has anybody seen this before? What am I doing wrong?
I have an EditText. I am using this for entering the mobile number of different countries. As soon as the user starts entering the number , i start formatting it based on the country of the number . For example for indian number i show it as
98765 43210 , i.e a space after fifth character. Similarly for other countries i use different formatting patterns.
But at the time of deleting the number from the keypad i am facing an issue. When the user clicks backspace on softkeypad , one character gets deleted.As i am overriding the AfterTextChanged method of EditText , so it gets called . In this method i check if the formatting is disturbed due to erasing the character . And i try to reformat the remaining number , and set the reformatted text again on edittext. This works properly.
But when user longpresses the backspace in order to delete the entire phone number in one go ,Then there is a problem as described below:
Keypad's backspace is pressed (So focus is on keypad), one character got deleted, AfterTextChanged got called , In AfterTextChanged method, I reformatted the text and set the reformatted text again on edittext using editText.setText(String), As i set the text, focus went to edittext , keypad lost the focus .so keypad is no longer pressed. (I can see the keypad backspace getting unpressed on UI after one character is deleted. Even though i have not lifted the my finger from backspace)
As a result it deleted only one character and stopped.
I know if the donot set the reformatted text on the editText in AfterTextChanged, then longpress will work and is working. But i need to set this text to show dynamic formatting of number .
But i also want to delete the phone number in one go , when the user longpresses the backspace of softkeypad.
Please help me how can i achieve this.
Use the setOnLongClickListener or compare your character length once the backspace is pressed to the previous value and ignore your AfterTextChanged event?
I have one simple app that suppose to get information from user and send an e-mail.
I have required fields, and if the user does not fill these fields they turn into red after pushing the BUTTON. I manage to change the color
The color suppose to change immediately after pressing the BUTTON, but what happens is, after clicking the button, in order the change the color(all the fields) I need to touch one of the Edit Text fields, then they change. (does not matter which one to touch, required ones or not.)
Here is my implementation for one of the fields,
if(etBayiiKodu.getText().toString().matches("")){
Log.d("BayiiKodu","NO STRING***1***");
etBayiiKodu.getBackground().setColorFilter(Color.rgb(255, 133, 145),Mode.MULTIPLY);
Log.d("BayiiKodu","NO STRING***2***");
allFilled=allFilled&&false;
}
else{
girilenSiparis.setBayiiKodu(String.valueOf(etBayiiKodu.getText()));
etBayiiKodu.getBackground().setColorFilter(Color.WHITE,Mode.MULTIPLY);
allFilled=allFilled&&true;
}
What could be reason for this?
Thank you...
Try calling .invalidate() on each view who's color is being changed.
I have a few forms that the user has to fill in and I use EditText to enter the information.
the problem is, when the user uses the virtual keyboard there no information about which field he is filling in.
so its fine when there is only one field but when he has 4 or more he fills in the first one, presses next and he has to remember what was the second field and so on
is there a way to set a title in the EditText so that instead of being just a text zone it has a title to remind the user what he is inputing ?
You can add a hint, which pre-fills the EditText with a useful reminder (in a faded-out colour). This disappears when the user starts typing.
android:hint="Type your name here"
Unfortunately the input method editor bits don't let you do that (though that would be nice). Try setting the attribute android:imeOptions="flagNoExtractUi" on the EditText instances.