0
public class Class1View extends LinearLayout{

   @Override
   protected void onFinishInflate(){
     super.onFinishInflate();    
     Butterknife.bind(this);    
   }   
}

How do I create a new view, for example, a new Button() and add it to this Class1View

I tried,

Butterknife.bind(this, new Button(getContext());

but it does not work.

dcanh121
  • 4,665
  • 11
  • 37
  • 84
  • Butterknife is for linking existing views with your code. If you want to inflate new views you have to do this the old way like LayoutInflater.from(Context).inflate(...) or just create the Button and add it to an existing view (which could be retrieved by Butterknife) – and_dev Nov 24 '15 at 08:45

1 Answers1

1

As per my understanding, Butterknife is there to help you bind a View element which is declared somewhere in XML. Since you're extending a View and want to add more Views within it dynamically, butterknife here is no use.

fluffyBatman
  • 6,524
  • 3
  • 24
  • 25