3

I follow the below tutorial and successfully implement autocomplete edit textbox and show all the suggestions as item list. I want to hide softkeyboard whenever I touch the item list and that option goes to the edit textbox.

http://www.claytical.com/blog/android-dynamic-autocompletion-using-google-places-api#comment-form

I tried number of options but nothing works. How can I achieve this and implement in an app?

Brian
  • 14,610
  • 7
  • 35
  • 43
Sajal Mittal
  • 103
  • 2
  • 12
  • Onsettouchlistner, onclick etc with adapter as adapter.onsettouchlistner and call hidesoftkeyboard function which is working fine – Sajal Mittal May 18 '15 at 04:54
  • 1
    Solution tried http://stackoverflow.com/questions/23903141/auto-hides-keyboard-after-scrolling-listview-on-android – Sajal Mittal May 18 '15 at 14:09

2 Answers2

5

It's working for me I just replaced

this:

in.hideSoftInputFromWindow(arg1.getWindowToken(), 0);

with:

in.hideSoftInputFromWindow(arg1.getApplicationWindowToken(), 0);

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
  • Please don't post the exact same answer to multiple questions: it's either not a good fit for all or the questions are duplicates which should be flagged/closed as such. – kleopatra Sep 21 '15 at 09:10
  • Thanks @Shylendra for your suggestion. I will try your solution and get back to you. – Sajal Mittal Sep 22 '15 at 12:40
1

So once you click on one of the autocomplete suggestions and you want the softkeyboard to hide... you need to implement an onClickListener on the selected autocomplete option so that is can hide the soft keyboard as soon as you make a selection after clicking that one.

Create an instance of the autocompleteTextView

AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.resource);

Implement onClicklistener to hide the soft keyboard using the InputManager.

text.setOnItemClickListener(new OnItemClickListener() {

  @Override
  public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    in.hideSoftInputFromWindow(arg1.getWindowToken(), 0);

  }

});

Hope this Helps!!

AniV
  • 3,997
  • 1
  • 12
  • 17
  • hello AniV, we need to create instance of autocompletetextview (main textview) or textview used for item list (TextView check = (TextView)findViewById(R.id.resource)) as shown below in the xml files. Please refer to the link posted in the question. – Sajal Mittal May 19 '15 at 10:47
  • Hi AniV, i tried your solution but it doesn't works. Let me tell you the problem again. Whenever you type something in autocompletetextview it shows you the list of suggestions and i want whenever i touch any suggestion softkeyboard hides. – Sajal Mittal May 19 '15 at 16:17
  • textView = (AutoCompleteTextView)findViewById(R.id.destination); textView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView > arg0, View arg1, int arg2, long arg3) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(arg1.getWindowToken(), 0); } }); – Sajal Mittal May 19 '15 at 16:23
  • Above code shows you the implementation of your solution under the onCreate() method – Sajal Mittal May 19 '15 at 16:24