CheckBox Text Not Set Correctly in Composite View After Fragment's First onCreateView
<p>I have an app that uses a composite view to show multiple similar type views in a fragment.  One custom part of these composite views is the text set for a CheckBox in each composite view.  The first time the fragment's lifecycle displays the content for the view all is fine (each checkbox has the correct text as specified in the fragment's xml using attributes),  but on each subsequent view (after orientation change or navigating via tabs) all the CheckBox texts are set to the same value (the last composite view's checkbox text value).</p>

<p>My composite view's xml layout info.
<strong>composite_view.xml:</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;merge xmlns:android="http://schemas.android.com/apk/res/android"&gt;  
  &lt;CheckBox
    android:id="@+id/myCheckBox" 
    style="@style/CheckBoxLeftAligned" 
    android:checked="false"
  /&gt;
  ...
&lt;/merge&gt;
</code></pre>

<p>My attributes file to allow for specific text to be set for each composite view's checkbox.
<strong>attributes.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
  &lt;declare-styleable name="ZZZ"&gt;
    &lt;attr name="name"   format="string" /&gt;              
  &lt;/declare-styleable&gt;
&lt;/resources&gt;
</code></pre>

<p>My fragment's layout which contains four of my composite views.
<strong>fragment_layout.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ctd="http://schemas.android.com/apk/res/com.xxx.yyy"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"&gt;
  &lt;RelativeLayout 
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;

    &lt;com.xxx.yyy.ui.zzz
      android:id="@+id/aaa"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      ctd:name="@string/aaa"
    /&gt;
    &lt;com.xxx.yyy.ui.zzz
      android:id="@+id/bbb"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      ctd:name="@string/bbb"
    /&gt;
    &lt;com.xxx.yyy.ui.zzz
      android:id="@+id/ccc"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      ctd:name="@string/ccc"
    /&gt;
    &lt;com.xxx.yyy.ui.zzz
      android:id="@+id/ddd"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      ctd:name="@string/ddd"
    /&gt;
  &lt;/RelativeLayout&gt;
&lt;/ScrollView&gt;
</code></pre>

<p>My composite view's java implementation.
<strong>zzz.java</strong></p>

<pre><code>package com.xxx.yyy.ui;

... 

public class zzz extends RelativeLayout {

  private static final String TAG = zzz.class.getSimpleName();

  private final Context mContext;

  private CheckBox mLabelCheckBox;


  public SimplePay(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;

    initializeLayoutBasics(context);
    processAttributeInformation(context, attrs);


  }

  private void initializeLayoutBasics(Context context) {
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.composite_view, this);    
  }

  private void processAttributeInformation(Context context, AttributeSet attr) {
    mLabelCheckBox = (CheckBox) findViewById(R.id.myCheckBox);

    final TypedArray a = context.obtainStyledAttributes(attr, R.styleable.ZZZ);
    String text = a.getString(R.styleable.ZZZ_name);
    mLabelCheckBox.setText(text);
    Log.d(TAG, "CheckBox=" + mLabelCheckBox.toString() + ", Title= " + payName);            

    a.recycle();
  }

  ...
}
</code></pre>

<p><strong>CatLog output</strong></p>

<pre><code>03-10 08:20:31.151: D/MyFragment(400): MyFragment.onAttach
03-10 08:20:31.151: D/MyFragment(400): MyFragment.onCreate
03-10 08:20:31.151: D/MyFragment(400): MyFragment.onCreateView
03-10 08:20:31.200: D/zzz(400): CheckBox=android.widget.CheckBox@40a78e00, Title= MSP
03-10 08:20:31.220: D/zzz(400): CheckBox=android.widget.CheckBox@40a9da58, Title= ISP
03-10 08:20:31.239: D/zzz(400): CheckBox=android.widget.CheckBox@40aa1248, Title= ASP
03-10 08:20:31.250: D/zzz(400): CheckBox=android.widget.CheckBox@40aa4a88, Title= Board Certified Pay
03-10 08:20:31.260: D/zzz(400): CheckBox=android.widget.CheckBox@40aa8310, Title= HPO Board Cert Pay
03-10 08:20:31.270: D/MyFragment(400): MyFragment.onStart
03-10 08:20:31.270: D/MyFragment(400): MyFragment.onResume
03-10 08:20:32.410: D/App(400): onTabUnselected detaching fragment MyFragment
03-10 08:20:32.426: D/App(400): onTabSelected adding fragment OtherFragment
03-10 08:20:32.440: D/MyFragment(400): MyFragment.onPause
03-10 08:20:32.450: D/TotalPayFragment(400): OtherFragment.onCreateView
03-10 08:20:32.519: D/TotalPayFragment(400): OtherFragment.onStart
03-10 08:20:33.120: D/App(400): onTabUnselected detaching fragment OtherFragment
03-10 08:20:33.120: D/App(400): onTabSelected attaching fragment MyFragment
03-10 08:20:33.170: D/MyFragment(400): MyFragment.onCreateView
03-10 08:20:33.190: D/SimplePay(400): CheckBox=android.widget.CheckBox@40acb618, Title= MSP
03-10 08:20:33.201: D/SimplePay(400): CheckBox=android.widget.CheckBox@40ace530, Title= ISP
03-10 08:20:33.210: D/SimplePay(400): CheckBox=android.widget.CheckBox@40ad1c20, Title= ASP
03-10 08:20:33.230: D/SimplePay(400): CheckBox=android.widget.CheckBox@40ad5310, Title= Board Certified Pay
03-10 08:20:33.280: D/SimplePay(400): CheckBox=android.widget.CheckBox@40ad8ad8, Title= HPO Board Cert Pay
03-10 08:20:33.290: D/MyFragment(400): MyFragment.onStart
03-10 08:20:33.290: D/MyFragment(400): MyFragment.onResume
</code></pre>

<p>So even my catlog output shows that each of my checkboxes is being set to the specific text that I have set in my fragment's xlm using attributes. By after the second time my fragment goes through onCreateView all of the CheckBox text values are set to "HPO Board Cert Pay".  This output is using a Honeycomb emulator.</p>

<p>I have used this same pattern when setting the text in TextBoxes in a composite view, so I am betting this has something to do with Checkboxes.</p>

<p>Any thoughts?</p>
