Does anyone have ideas on how to achieve a blank indent on the first line of an EditText such that the user cannot modify the indent?
My goal is to superimpose some other info (possibly graphics) in the indent area and still allow the rest of the EditText to wrap long lines back to the normal left margin.
Fallback would be to add a separate line or column for the "other info", but that isn't as good a use of the screen real estate.
Perhaps there is better way to do this. Suggestions are welcome!
I'm not sure on what are you trying to do but you can "modify" dinamically the text while is prompted.
Use a TextWatcher that offers you three method called in order. Try in debug with some breakpoints to understand better the variables and use them!
((EditText) findViewById(R.id.myEditText)).addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
#Override
public void afterTextChanged(Editable s) {}
});
Related
Update: Solved.
I am using EditText as Label display.
I added these lines in XML, but no change.
android:cursorVisible="false"
android:inputType="textMultiLine|textNoSuggestions"
android:textIsSelectable="false"
In code side, added this line:
editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
I tried all of those settings, none of theme helped, also used all of them together still does not work.
What is the appropriate way?
Use this tag in your xml will fix suggestion problem:
android:inputType="textFilter|textMultiLine"
but for backspace or delete problem you can use addTextChangedListener like this:
editText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// here you can check the changes and revert change or anything you like
}
#Override
public void afterTextChanged(Editable s) {
}
});
for more detail see the official docs of TextWatcher
Below is an example that replicates my lagging problem. Once I set the text on the EditTextView it takes at least 1.5 seconds for the user to be allowed to input another character.
amountEditText.addTextChangedListener(new TextWatcher() {
#Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
#Override public void afterTextChanged(Editable s) {}
#Override public void onTextChanged(CharSequence s, int start, int before, int count) {
String amount = s.toString();
if( !amount.equals(current )) {
amountEditText.removeTextChangedListener(this);
amountEditText.setText(s);
Selection.setSelection(amountEditText.getText(), amountEditText.getText().length());
amountEditText.addTextChangedListener(this);
}
}
});
I've searched around and have not found a solution.
I identified that the issue was coming from the textView.setText() call.
The solution was to not use setText(), instead use the Editable that is provided to you in the onTextChanged callback.
I tried to use the Editable before, however i couldn't get it working with inputs such as "$12,000".
This was due to having InputFilters still attached to the Editable.
Regards,
Scott.
It lags because you remove and then readd your listener.
You seems to be trying to select the text inside the EditText. To do so, simply set editText.setSelectAllOnFocus(true); or android:selectAllOnFocus="true" in xml. Then remove the entire TextChangedListener from your code.
According to me it is most probably because of trying to remove (amountEditText.removeTextChangedListener(this);) and add (amountEditText.addTextChangedListener(this);) the Text Change Listener every time. I would recommend you to replace your code without those adding and removal.
Hope this helped.
My task is to detect the text changes in the TextView of my app, as close to real time as possible. However, with Swype-style virtual keyboards like SwiftKey, the whole word appears at once. Is there any way to at least detect that user is doing some actions with the virtual keyboard, like moving the finger on it?
Use Textwatcher. You will be able to see every change. This work with EditText and TextView(Even if I never tried with a TextView)
#Override
public void afterTextChanged(Editable s){
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count){
}
And you juste have to add it with :
TextView.addTextChangedListener(TextWatcher)
I have 3 widgets on my screen, Text View, Edit Text and a Button. What ever I insert in my edit text, when I click the button, the text view gets the string from the edit text. Now, what I want to do is that, if I have already inserted the character "\" or "," or what ever character I want, it will not be inputted anymore. It's like, you can only put that character once in the edit text. Do you guys have any idea about it?
Well what I am thinking is that, I have to search from the edit view then validate it. But I don't know what code to use. Could somebody please help me? Thank you!
Use Android TextWatcher on EditText.
There are delegates which returns the charsequence that is entered
onTextChanged
afterTextChanged
beforeTextChanged
Fill the entered character in set everytime. If size is not incrementing that means a duplicate.
then avoid adding of that character in edittext
I think you need to add a TextChangedListener to your editText.
et.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
I need to control pressed buttons, before they goes to my EditText widget. It's should work like filter.
For example: I need that user could fill EditText only with digits 1,2,3,4,5 other symbols must be ignored. So the part of buttons on virtual keyboard should be disabled or I need to catch last pressed symbol, analyze it and disable for EditText.
Who knows the way how to solve this problem?
Thanks..
statusEdt.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//do stuff
charTxt.setText(statusEdt.getText().length() + "/140");
}
});
I used this TextChangedListener(TextWatcher) to keep a count of how many characters had been typed into an EditText for a Twitter client I made. You could probably use a listener like this. You'll want to override beforeTextChanged or onTextChanged. These methods will pass you whatever CharSequence has been typed. You can check what was typed in and if it is not valid input you can remove it by calling setText() and passing in whatever has been typed so far minus the invalid characters.
What you probably need is an InputFilter.
For example to allow only digits, sign and decimal point:
editText.setFilters(DigistKeyListener.getInstance(true, true));