[ACCEPTED]-AutoCompleteTextView onItemSelectedListener does not work-android

Accepted answer
Score: 111

Dude, you will laugh at your mistake. Its 8 working for me. You have added OnItemSelectedListener and not 7 OnItemClickListener.

Your method will only work if you select 6 your items or browse through the view using 5 a trackball or up/down arrows. Use one more 4 value in your String starting with "k" say 3 Karen1. Type "k" and select between Karen 2 and Karen1.You will see that it works. If 1 you want click, then add OnItemClickListener and override

public void onItemClick(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3)
Score: 16

You must use

OnItemClickListener

instead 1 of OnItemSelectedListener

Score: 4

Looks like, of-late, the real problem may 7 not be in the code of the question asked, but 6 in the source code of the AutoCompleteTextView class itself.

Although 5 the AutoCompleteTextView class sets it's OnItemSelectedListener through the setOnItemSelectedListener method, but 4 nowhere in the class any listener method is called. Hence the 3 listener remains unused. (reason best known 2 to developers!)

Source code here: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/AutoCompleteTextView.java

As such, the 1 alternative is to use the OnItemClickListener.

Score: 0

For JAVA

myAutoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                
                Log.e(tag, "Clicked!");
                myAutoCompleteTextView.clearFocus();
            }
        });

0

More Related questions