To Hide Keyword after input on EditText - android

I typed phone number into edittext. then i want to go next view, because of the next view hide by keyword, so how can i hide this, during this situation, how can i handle this?
enter image description here

To hide the soft keyboard after you have finished typing and clicked on enter button.
Textview.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//your content
}
/*This code will basically hide the keyboard*/
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
return false;
}
});
In this code after you have finished typing user will hit enter key and keyboard will hide the soft keyboard.

Related

Listening for Done doesn't close soft keyboard

I have added a setOnEditorActionListener for my EditText so I can catch press of "Done" button. While it works like you can see in the code below and enters the if() section, keyboard stays open and doesn't close.
What do I have to change so I can still catch the press of "Done" button and close the keyboard ?
etCompany.setOnEditorActionListener(new BackEventEditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
((GetStartedActivity) getActivity()).isKeyboardOpen = false;
setVisibleContent();
return true;
}
return false;
}
});
You can force close it with
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(textView.getWindowToken(), 0);

Android - How to hide keyboard when search button of the keyboard is pressed?

How to hide keyboard when search button of the keyboard is pressed?
When the user finishes inputing in edittext and press 'search button' fo the keyboard, the keyboard should be hidden..
Set imeOptions to "actionSearch" in your xlm for edit text
Initialize listeners for your EditText
searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
Hide keyboard when user clicks search.
private void performSearch() {
searchEditText.clearFocus();
InputMethodManager in = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(searchEditText.getWindowToken(), 0);
... perform search ...
}

How to change Enter by Done from keyboard in a textMultiline?

this is my editext:
EditText<br>
android:id="#+id/detailsText"<br>
android:layout_width="fill_parent"<br>
android:layout_height="wrap_content"<br>
android:inputType="textMultiLine"<br>
android:maxLength="500"/><br>
I have to hide the keyboard some how so y add this:
details.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {<br>
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {<br>
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);<br>
imm.hideSoftInputFromWindow(details.getWindowToken(), 0);
return true;
}<br>
return false;
}
});
When i press enter the keyboard get hide (that's what i want), but i need to change the arrow that the enter button have by default, I want to put something like "Done" and i cant change the android:inputType="textMultiLine" because the edit text change the size with the user input.
You can try this
android:imeOptions="actionDone"
This will automatically hide the keyboard with done button, you don't need to manually write code for it.

how can I auto-clear the text box and hide the keypad in android

How can I auto-clear the text box after I clicked the ADD button (inserted data) into database?
How to link the DONE button on keyPad(prompt out when user wants to type ) to my ADD button?
You'll need to use an OnEditorActionListener, where you click the button, hide the keyboard, and set the text to "". Like this:
mEditText.setOnEditorActionListener(new OnEditorActionListener(){
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
mButton.performClick();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
v.setText("");
return true;
}
});

After type in EditText, how to make keyboard disappear

From the android tutorial :
pass_text.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
return true;
}
return false;
}
});
}
when click at EditText, it has a keyboard appear on the frame. I want to know after Enter.
How to make keyboard out from frame except click Back.
Thank you
Try the following
For Activity:
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(curEditText.getWindowToken(), 0);
In case of Fragment :
InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
give the EditText box you have the attribute android:imeOptions="actionDone"
this will change the Enter button to a Done button that will close the keyboard.
A working approach to get rid of the soft keyboard is to disable and then enable the TextEdit field in the Return-key event, button-press event or whatever. For example:
....
pass_text.setEnabled(false);
pass_text.setEnabled(true);
....
I think we can simply add this attribute to our EditText:
android:inputType="text"
This will automatically force the text to be on a single line and therefore when we click Enter, the keyboard disappears.

Categories

Resources