title: Load CustomView and its logic at Runtime
body: <p>I'm creating a custom component for an Android App (exactly a volume fader for an audio mixer). It works fine.</p>
  
  <p>What I want is to load several instances of this component at Run-Time.
  I tried with this:</p>
  
  <pre><code>LinearLayout layout = (LinearLayout)findViewById(R.id.mixerContainer) //This layout
  for(int i=0;i&lt;8;i++){
    LayoutInflater l = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = l.inflate(R.Layout.MyVolumeFader, null);
    layout.add(v);
  }
  </code></pre>
  
  <p>This adds the view correctly, but doesn't attach all the logic of my component (that is contained in MyVolumeFader class).</p>
  
  <p>How can I solve this problem?</p>
  
  <p>--</p>
  
  <p>The code looks like:</p>
  
  <p><strong>MyVolumeFader.java</strong></p>
  
  <pre><code>public class MyVolumeFader extends RelativeLayout{
   [...]
  
   private VerticalSeekBar volumeBar;
  
   [...]
  
   -&gt;volumeBar handling&lt;-
  }
  </code></pre>
  
  <p><strong>MyVolumeFader.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout...
  Some TextViews, Buttons and a VerticalSeekBar are here...
  </code></pre>
  
  <p>Thank you.</p>