title: Compound control in other package
body: <p>I have added an easy compound control which loads its layout from a XML layout and implements own XML attributes.</p>
  
  <p>But this only works while this control is in the main package (<code>com.myapp</code>). When I try to move it into a subpackage like <code>com.myapp.controls</code> things begin to fail.</p>
  
  <p>This is the attrs.xml to define the control custom attributes:</p>
  
  <pre><code>&lt;resources&gt;
  
      &lt;declare-styleable name="CH2"&gt;
          &lt;attr name="textText" format="string" /&gt;
      &lt;/declare-styleable&gt;
  
      &lt;declare-styleable name="CH3"&gt;
          &lt;attr name="textFex" format="string" /&gt;
      &lt;/declare-styleable&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p>This is the control CH2.java which ia in subspackage and does <strong>not</strong> work:</p>
  
  <pre><code>package com.myapp.controls;
  
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.util.AttributeSet;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  public class CH2 extends LinearLayout {
  
      private TextView textView;
  
      public CH2(Context context) throws Exception {
          super(context);
          init(context, null);
      }
  
      public CH2(Context context, AttributeSet attrs) throws Exception {
          super(context, attrs);
          init(context, attrs);
      }
  
      private void init(Context context, AttributeSet attrs) throws Exception {
  
          this.setOrientation(LinearLayout.VERTICAL);
  
          LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          layoutInflater.inflate(com.myapp.R.layout.category_header, this, true);
  
          View v = findViewById(com.myapp.R.id.chText);
          this.textView = (TextView)v;
  
          if (attrs != null) {
              TypedArray a = getContext().obtainStyledAttributes(attrs, com.myapp.R.styleable.CH2);
  
              String text = a.getString(com.myapp.R.styleable.CH2_textText);
              this.textView.setText(text != null ? text : "&lt;NULL!&gt;");
  
              a.recycle();        
          }
      }
  }
  </code></pre>
  
  <p>This is CH3.java which works:</p>
  
  <pre><code>package com.myapp;
  
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.util.AttributeSet;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  public class CH3 extends LinearLayout {
  
      private TextView textView;
  
      public CH3(Context context) throws Exception {
          super(context);
          init(context, null);
      }
  
      public CH3(Context context, AttributeSet attrs) throws Exception {
          super(context, attrs);
          init(context, attrs);
      }
  
      private void init(Context context, AttributeSet attrs) throws Exception {
  
          this.setOrientation(LinearLayout.VERTICAL);
  
          LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          layoutInflater.inflate(com.myapp.R.layout.category_header, this, true);
  
          View v = findViewById(com.myapp.R.id.chText);
          this.textView = (TextView)v;
  
          if (attrs != null) {
              TypedArray a = getContext().obtainStyledAttributes(attrs, com.myapp.R.styleable.CH3);
  
              String text = a.getString(com.myapp.R.styleable.CH3_textFex);
              this.textView.setText(text != null ? text : "&lt;NULL!&gt;");
  
              a.recycle();        
          }
      }
  }
  </code></pre>
  
  <p>Both sources use the same category_header.xml. The layout is loaded without problem. I can use both like this:</p>
  
  <pre><code>&lt;com.myapp.controls.CH2
      android:id="@+id/cH1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
      myns:textText="Test 1" &gt;
  &lt;/com.myapp.controls.CH2&gt;
  
  &lt;com.myapp.CH3
      android:id="@+id/cH2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
      myns:textFex="Test 2"
      &gt;
  &lt;/com.myapp.CH3&gt;
  </code></pre>
  
  <p>How can I make CH2 work? Or is it impossible to use another package?</p>
  
  <p>Sidequest: Can I make both controls to use the same XML attribute <code>textText</code> or will they always have to use different attributes? Or can the declareable-style name be different from the components name?</p>
  
  <hr>
  
  <p>Another approach with a new declare-styleable:</p>
  
  <pre><code>&lt;declare-styleable name="controls.CH2"&gt;
      &lt;attr name="textText" format="string" /&gt;
  &lt;/declare-styleable&gt;
  </code></pre>
  
  <p>But it does not seem to be usable. XML view always says <em>Unexpected text found in layout file:</em>, regardless how I use CH2:</p>
  
  <pre><code>xmlns:myns="http://schemas.android.com/apk/res/com.myapp"
  xmlns:mynsc="http://schemas.android.com/apk/res/com.myapp.controls"
  ...
  &lt;com.myapp.controls.CH2
      android:id="@+id/cH1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
      mynsc:textText="TestTestTest" 
      &gt;        
  &lt;/com.myapp.controls.CH2&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>xmlns:myns="http://schemas.android.com/apk/res/com.myapp"
  ...
  &lt;com.myapp.controls.CH2
      android:id="@+id/cH1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
      myns.controls:textText="TestTestTest" 
      &gt;        
  &lt;/com.myapp.controls.CH2&gt;
  </code></pre>