Butterknife: AutoCompleteTextView does not work with @OnItemClick

Created on 14 Feb 2014  路  7Comments  路  Source: JakeWharton/butterknife

  • 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.

Most helpful comment

I have the same problem

All 7 comments

@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.

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

This feature will be nice!

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

Not sure if and when this will be merged.

me too! How to fix this ?

I have the same problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

galibimtiaz picture galibimtiaz  路  3Comments

ZakTaccardi picture ZakTaccardi  路  3Comments

sdobek picture sdobek  路  4Comments

rajivenator picture rajivenator  路  4Comments

engr-umar-qureshi picture engr-umar-qureshi  路  3Comments