Using Butterknife to inject an array of views

Currently I have this array of views:

ImageView activityImageViews[] = {
    (ImageView) rootView.findViewById(,
    (ImageView) rootView.findViewById(,
    (ImageView) rootView.findViewById(,
    (ImageView) rootView.findViewById(

Is there a way I could use Butterknife to inject all those views? I need to keep them in an array (or in a way so I can iterate over them).

  • Destroy item from the ViewPager's adapter after screen orientation changed
  • Building Android from source - emulator and AVDs
  • How to add the bubbles to textview android?
  • <size> attribute not useful when using layer-list?
  • returns null
  • Android WebView style background-color:transparent ignored on android 2.2
  • Android ListView headers
  • Center text in a toast in Android
  • what causes “constant expression required” errors for the generated values in switch statements?
  • How to make an android app return to the last open activity when relaunched?
  • Android intent filter for a particular file extension?
  • ADB Error codes
  • 2 Solutions collect form web for “Using Butterknife to inject an array of views”

    Currently it is possible to inject several views as array. From ButterKnife documentation (see VIEW LISTS section)

    @InjectViews({,, })
    List<EditText> nameViews;

    Same thing for multiple click listeners:

    @OnClick({,, })
    public void pickDoor(DoorView door) {
      if (door.hasPrizeBehind()) {
        Toast.makeText(this, "You win!", LENGTH_SHORT).show();
      } else {
        Toast.makeText(this, "Try again", LENGTH_SHORT).show();

    I suppose that the elements added to the Array are dynamically, otherwise you can simply declare them in your header one by one and afterwards add them to the array:

    // in the header:
    @InjectView( ImageView imageView1;
    @InjectView( ImageView imageView2;
    @InjectView( ImageView imageView3;
    // inside your code:
    ImageView activityImageViews[] = {
        imageView1, imageView2, imageView3

    But however, if the elements are dynamic (in amount of elements/id of elements etc.) the only thing you can do is to use ButterKnife.findById which will spare the ImageView cast – you can’t inject them via annotation because Butterknife does not know what to generate/inject on compile time (the information is first available on runtime).

    ImageView activityImageViews[] = {
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.