AutoCompleteTextView onItemSelectedListener does not work

前端 未结 3 435
挽巷
挽巷 2020-12-16 09:26

I have an AutoCompleteTextView and set onItemSelectedListener to it, which does not work.

Have you any idea what is the problem? Here is my Activity, I can also pr

相关标签:
3条回答
  • 2020-12-16 09:51

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

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

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

    As such, the alternative is to use the OnItemClickListener.

    0 讨论(0)
  • 2020-12-16 10:03

    You must use

    OnItemClickListener

    instead of OnItemSelectedListener

    0 讨论(0)
  • 2020-12-16 10:07

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

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

    public void onItemClick(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3)
    
    0 讨论(0)
提交回复
热议问题