butterknife icon indicating copy to clipboard operation
butterknife copied to clipboard

AutoCompleteTextView does not work with @OnItemClick

Open jeffdcamp opened this issue 11 years ago • 7 comments

  • For the code: @InjectView(R.id.item) AutoCompleteTextView autoCompleteTextView; ...

    @OnItemClick(R.id.item) public void onMyItemClick(long id) { ... }

  • During runtime the following exception will be thrown: java.lang.ClassCastException: android.widget.AutoCompleteTextView cannot be cast to android.widget.AdapterView

  • Cause (from ...$$ViewInjector.java): target.autoCompleteTextView = (android.widget.AutoCompleteTextView) view; ((android.widget.AdapterView) view).setOnItemClickListener( // <-- !!! ERROR !!! new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick( android.widget.AdapterView<?> p0, android.view.View p1, int p2, long p3 ) { target.onMyItemClick(p3); } });

  • Error Reason: AutoCompleteTextView does not extend/implement AdapterView

  • Notes AutoCompleteTextView DOES have a setOnItemClickListener(android.widget.AdapterView.OnItemClickListener ) method, just like ListView. I don't know what other widgets may run into this same issue.

jeffdcamp avatar Feb 14 '14 19:02 jeffdcamp

@OnItemClick is for AdapterViews and AutoCompleteTextView is not a child of it. It has an instance of the AdapterView to display the contents of suggestions, but you have no access to that member, so you should use common way for adding an item click listener.

vbevans94 avatar Jun 02 '14 18:06 vbevans94

I have added a new Annotation (@OnAutoCompleteItemClick) and submitted a pull request https://github.com/JakeWharton/butterknife/pull/242

manijshrestha avatar Mar 14 '15 20:03 manijshrestha

This feature will be nice!

sandrocsimas avatar Aug 13 '15 00:08 sandrocsimas

Hi, I am also having this issue, any ideas when this will be merged? Thanks

valllllll2000 avatar Sep 01 '15 12:09 valllllll2000

Not sure if and when this will be merged.

manijshrestha avatar Sep 01 '15 13:09 manijshrestha

me too! How to fix this ?

chubecode avatar Jun 06 '17 02:06 chubecode

I have the same problem

javichaques avatar Jan 05 '18 09:01 javichaques