Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep DropDownList of AutoCompleteTextView opened after pressing the Back key?

i am using AutoCompleteTextView in my Activity and i need it's DropDownList to be shown all the time (it's the only View in Window), even after Back key press. I need to dismiss soft keyboard instead.

I tried to override Activity's onBackPressed method, but it's not used at all, so BackPressed event is being handled somewhere "higher". So i tried to find out where, but AutoCompleteTextView has no onBackPressed method defined.

Any advices?

like image 390
filipko Avatar asked Mar 15 '12 14:03

filipko


People also ask

What is auto complete text view?

An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

How do I get the selected position in AutoCompleteTextView?

Use List instead of Array. Implement onItemClickListener for AutoCompleteTextView, then use indexOf on your list to find the index of selected item. Show activity on this post. Show activity on this post.

How do you get the ID of the selected item of the AutoCompleteTextView in Android?

Just call your adapter. getItem(position) and you will get the output you want. For example skillLevelAdapter. getItem(position).


1 Answers

You can create your custom AutoCompleteTextView and Override the method onKeyPreIme(int keyCode, KeyEvent event)

I also realized that this method is called 2 times, I'm running my code only in the second time. Here is the example:

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == 1) {
        //add your code here
        return true;
    }
    return super.onKeyPreIme(keyCode, event);
}
like image 188
Blu7 Avatar answered Oct 09 '22 08:10

Blu7