How to detect user activity on the keyboard - android

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)

Related

How to get text from EditText and Show on ActionBar?

I have EditText in which user type their Account Number. Now what i want that when user stop typing his Account Number in EditText then i want to show that Account Number in ActionBar. How can i achieve this ?
Try using a TextWatcher. Something like this:
editText.addTextChangedListener(new TextWathcer(){
void beforeTextChanged(CharSequence s, int start, int count, int after){}
void onTextChanged(CharSequence s, int start, int before, int count){}
void afterTextChanged(Editable s){
getSupportActionBar().setTitle(s.getText().toString());
}
});
This code may work:
getSupportActionBar().setTitle(editText.getText().toString());
If you want set the title in the right of the action bar, It is recommended to use Toolbar for you can custom the layout.

Android: How to keep Default number always even if user wants to delete it, and how to delete default number when user inputs a value?

I have a simple EditText, which inputs only numbers.
I want to show 0(zero) even if user presses backspace.
Now zero is getting deleted.
Moreover, I need to remove this default zero, when user starts entering values.
How do i achieve it?
You should use android:hint="0" or in more complex way..
You should use TextWatcher and override the below three methods. THer you can get the text in the arguments as CharSequence in the beforeTextChanged and onTextChanged methods and in afterTextChanged you have Editable from where you can get the data in the EditText. Write in the desired function as per your logic and it should work like a charm.
editText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(final CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
It sounds like you want:
<EditText
android:hint="0" />

Entering Decimal value in Edit text dynamically

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());
}
});

need EditText with readonly indent

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) {}
});

EditText error message with keyboard change affecting the theme/style

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));
}
}
};

Categories

Resources