How can i hide/disable done button on soft keyboard android? - android

I am working with Amazon S3 api.
Problem: Working with TextWatcher. As soon as user enters more than 3 characters in the edittext, api is called and it shows matched results. The problem starts as soon the user hit the done/enter button on soft keyboard, the api is called again and it searches again. Can i stop this second call somehow? Thanks!

you can change it from xml:
<EditText
...
android:imeOptions="actionNone"/>
or from code:
editText.setImeOptions(EditorInfo.IME_ACTION_NONE);
It will remove the done button whenever user trigger the softkeybord

Maybe you can try to override the onKeyListener method in your control, to let it detect if the key pressed is 'enter' and add the code you want your 'enter' key to do ?
edittext.setOnKeyListener(new View.OnKeyListener() {

just handle done click and hide the soft keyboard
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// hide your keyboard here
try {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && activity.getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
return false;
}
});

Add
android:maxLines="1"
to you xml and enter button should be disabled.

You can Do like editText.setImeOptions(EditorInfo.IME_ACTION_NONE);
but it won't hide the Enter/Next

Related

Hide keyboard after user searches?

I have an activity where there is an EditText and on enter key search results are shown, so what I simply want to do is to close the keyboard when search results are about to show to prevent the user from having to do it. However if the user wants to refine his search the keyboard should open back up if he taps into the EditText again.
This has been more difficult than I imagined, I've been search and tried a few things most don't even close the keyboard on my HTC, one method where the InputType is set to INPUT_NULL closes the keyboard but it doesn't open afterwards.
Any suggestions on how to do this?
#Override
public boolean onQueryTextSubmit(String query) {
// Your search methods
searchView.clearFocus();
return true;
}
Straight to the point and clean.
The right way to do this:
set imeOptions to "actionSearch"
initialize listeners for input and search button(if provided)
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;
}
});
view.findViewById(R.id.bigSearchBar_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
performSearch();
}
});
Hide keyboard when user clicks search. To ensure that keyboard won't show when user minimizes and restores Activity you have to remove focus from EditText
private void performSearch() {
searchEditText.clearFocus();
InputMethodManager in = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(searchEditText.getWindowToken(), 0);
... perform search ...
}
I belive this code snippet will close the keyboard:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
if not try this one:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
let me know if these work

How to add a Button on top of an Android keyboard

Hi guys i was assigned a task in my project,there i need to add a Done button on the top of Android keyboard.In my screen i have an EditText,whenever i click on the EditText it should open a keyboard along with the "Done" Button on the top of an Android keyboard.So that i can attach a Listener to that button to perform my task.Any Suggestions.
Thanks&Regards,
E.N.Krishna.
If you need the keyboard to display the Done button, you need to define this in your EditText
<EditText android:text="EditText" android:layout_width="fill_parent"
android:id="#+id/editText1" android:layout_height="wrap_content"
android:imeOptions="actionDone"/>
You can then catch when the user presses the Done button by using OnEditorActionListener
class DoneOnEditorActionListener implements OnEditorActionListener {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
}
Your answer could be found if you read this.
Namely the concept of IME action.

EditText with soft keyboard and "Back" button

When I'm using "EditText" I have the virtual keyboard.
Pressing first time "Back" button hides the keyboard. Second press invokes "onBackPressed" callback in my activity. OK, but...
I have no idea how to hook the very first press. I need to process input data as soon as the virtual keyboard dismissed.
Any ideas are welcome.
Thanks.
You can override when the keyboard disappears using this method:
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK &&
event.getAction() == KeyEvent.ACTION_UP) {
// Do your thing here
return false;
}
return super.dispatchKeyEvent(event);
}
Taken from my other answer # : Android: Error popup on EditText doesn't move down when keyboard goes away
Custom Back Button:-
final RelativeLayout rrBack = (RelativeLayout) mCustomView.findViewById(R.id.rr_back);
rrBack.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
MyApplication.getInstance().getRequestQueue().cancelAll(FEED_DETAIL_TAG_REQUEST);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(rrBack.getWindowToken(), 0);
}
});

Take the text from EditText without a Button

I'm avoiding to use a button to retrieve the text of an EditText. It is possible to take the confirmation when an user just confirm from the keyboard?
Here's a code snippet that takes an enter from the keyboard, and dismisses the soft keyboard from the screen when the user confirms:
txtUserWord.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode,KeyEvent event){
if((event.getAction()==KeyEvent.ACTION_DOWN)&&
(keyCode==KeyEvent.KEYCODE_ENTER)){
inputWord = txtUserWord.getText().toString();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtUserWord.getWindowToken(),0);
return true;
}
return false;
}
});
take a look at this previous post:
Setting the Return key on the Android keyboard

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