android - @OnClick array with optional ids (ButterKnife) -


i have activity inflates view when web request finished. of widgets of view have attached 1 onclick method, have:

@onclick({r.id.bt1, r.id.bt2, r.id.inflated_bt1, r.id.inflated_bt2}) public void onclick(view view) {     // ... } 

as r.id.inflated_bt1 , r.id.inflated_bt2 don't exist when app created, throws exception suggesting set @optional annotation.

required view 'inflated_bt1' id xxxxxxxx method 'onclick' not found. if view optional add '@optional' annotation.

is there way set of views @optional annotation , inject them when view inflated? or, there way it?

thank you

the correct answer use @nullable annotation. see butterknife home page. usage example:

import android.support.annotation.nullable;  @nullable @onclick(r.id.maybe_missing) void onmaybemissingclicked() {     // todo ... } 

edit:

in year since wrote answer , accepted, butterknife docs changed, , current preferred method accomplishing use @optional annotation. since accepted answer, feel important update address current practice. example:

import butterknife.optional;  @optional @onclick(r.id.maybe_missing) void onmaybemissingclicked() {     // todo ... } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -