How to get text from EditText and Show on ActionBar? - android

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.

Related

How to detect user activity on the keyboard

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)

Display warning when NumberPicker number exceed Max on Keyboard Entry

I have a Number Picker that allow user to enter some number within a fixed range.
By default the number will not allow the user to enter a number larger than the max set for the number picker.
However i would like to display a message when that happens. Is there a way to access the edittext in the number picker ? Thanks.
You can implement TextChangedListener that will register every change in the field so that you can act accordingly on it.
for example.
yourEditText = (EditText) findViewById(R.id.yourEditTextId);
yourEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// you can call or do what you want with your EditText here
yourEditText. ...
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});

Editext validation android

In Edittext Android :
How to implement this feature if user entered any valid numeric value it should get displayed in the form of decimal value.
e.g If user enters 4 then it should get displayed as 4.000 instead of only 4.
Also can be done using DONE button click handler of virtual keypad.
You can use like this
EditText et = (EditText)findViewById(R.id.myEditText);
et.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){
//Check your et value and set it back.
// Retrieve 4.. set it to 4.000
}
});
Have you tried this on your XML?
android:inputType="numberDecimal"
Parse the string you are getting from editext to double or float in the click of a done button or wherever you want.

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

How can i add the gmail.com after # if i press the g ? in Email Edittext box

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

Categories

Resources