I have two edit texts, with validation to ensure that a value was entered for each box.
The problem is, when the keyboard is not displaying everything is ok, but when the keyboard is displayed the hover validation moves above the edittext and has a white background when it should be black.
Hopefully the images should show it better.
N.B it only happens on the below edittext, the top one is fine as the keyboard does not cover it once it is opened.
I have set the keyboard to not resize the screen, i.e.
android:windowSoftInputMode="stateHidden|adjustPan"
I think it may be an Acer issue on the Acer A501 tablet, as my Samsung Galaxy does not have this problem.
private TextWatcher mileageListener = 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) {
String start = mStartMileage.getText().toString().trim();
// check that start mileage has been entered
if ("".equals(start)) {
mStartMileage.setError(getText(R.string.validation_enter_start_mileage));
}
}
};
Related
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 am working in an Android application.In my application there is a edit text. in that
edit text if user enters 12, it has to change dynamically as 12.00. which means it only
accept decimal values. if user enters as 12.3 then it should become 12.30.and if 12.35
then it should be 12.35 only. it will not allow user to enter more than two after dot.
Please help in this scenario?
Use a TextWatcher to handle dinamically the input, then inside the TextWatcher use something like DecimalFormat to change the text.
yourEditText.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) {
// do something here
DecimalFormat form = new DecimalFormat("0.00");
String FormattedText=form.format(s.toString());
}
});
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) {}
});
I've noticed on other app that the size of the space bar strinks and changes to .com when user select the email field, How can i add the ".com" button on android keyboard.
How can we do the same thing? an we also auto fill gmail.com or homail.com or yahoo.com quickly by detecting the 1st character after #?
This is controlled by android:inputType. Try textUri.
To autoFill functionality see AutoTextField, or you can listen for edit action by using method
textMessage.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){}
});
and for KeyBoard feature, see Setting Virtaul KeyBoard Action key,
Android - cutomized keyboard key and action
Moving an app from 2.2 to 3.x, one of my EditText's that I was using a TextWatcher on for validation is behaving badly. In short, when a user clicks on the EditText and the entire word goes into 'suggestions mode' (where it is underlined), it effectively gets removed from the EditText from the TextWatcher's perspective, triggering my text validation check that I do for an empty EditText. The code:
mText = (EditText) findViewById(R.id.inpt_title);
mText.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable editable) {
final String title = editable.toString();
Log.d(LOG_TAG, "addTextChangedListener(): title: " + title + ", length: " + title.length());
if (title.length() == 0) {
// empty title
mText.setError(getString(R.string.error_note_title_empty));
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
mText.setTextColor(getResources().getColor(R.color.black));
}
#Override
public void onTextChanged(CharSequence s, int start, int count, int after) {}
});
I'd like to keep suggestions working, but there seems to be some weird interaction here.
Any way to either a) keep the EditText from being empty when the entire word is in 'suggestion mode', or at least checking to see if the EditText is in the 'suggestion' state to determine if the EditText is truly empty, or b) turing off suggestions? I've tried android:inputType="text|textCapWords|textNoSuggestions" for the EditText in question, as well as setting it via mText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); in the code above but suggestions keep happening on a Lenovo 3.1 tablet.
Update:
I see API 14 added a isInputMethodTarget() method to the EditText, which I could use to check for active suggestions and disable the validation... but I am running against API 12. Perhaps I could check the IME directly to see if the suggestions are active?