title: Call different Java parent constructor from Scala with Android
body: <p>I need to inherit <code>android.support.v4.view.ViewPager</code> and two constructors. In Java, it is done by:</p>
  
  <pre><code>class MyViewPager extend android.support.v4.view.ViewPager {
    public ViewPager(Context context) {
      super(context);
    }
  
    public ViewPager(Context context, AttributeSet attrs) {
      super(context, attrs);
    }
  }
  </code></pre>
  
  <p>I have searched on Google and here for a while, and some people suggested to implement this in Scala like this:</p>
  
  <pre><code>import android.support.v4.view.ViewPager
  
  trait ViewPagerTrait extends ViewPager {
    // ...implement ViewPager non-constructor functions here...
  }
  
  object MyViewPager {
    def apply(context: Context) = new ViewPager(context) with ViewPagerTrait
    def apply(context: Context, attrs: AttributeSet) = new ViewPager(context, attrs) with ViewPagerTrait
  }
  </code></pre>
  
  <p>The above Scala code compiles, but it it seems that the <code>apply</code> method is not invoked correctly when Android tries to build the view. I think that's because when the Android framework parses the XML file and tries to create the view object, it uses reflection to find the constructor, thus it is not using the <code>apply</code> methods</p>