title: Why EditText in a custom compound view is re-using the text entered in another compound view instance?
body: <p>I'm trying to write a custom compound view composed by a <code>TextView</code> and an <code>EditText</code>, _compound_view.xml_:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/compoundText"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" &gt;
  
  &lt;TextView
      android:id="@+id/textLabel"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Label" /&gt;
  
  &lt;EditText
      android:id="@+id/textEdit"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="enter text here" &gt;
  &lt;/EditText&gt;
  </code></pre>
  
  <p></p>
  
  <p>and this is the class extending <code>LinearLayout</code>:</p>
  
  <pre><code>public class CompoundView extends LinearLayout {
  
  public CompoundView(Context context, AttributeSet attrs) {
      super(context, attrs);
  
      readAttributes(context, attrs);
      init(context);
  }
  
  public CompoundView(Context context) {
      super(context);
  
      init(context);
  }
  
  private void init(Context c) {
  
      final LayoutInflater inflater = (LayoutInflater) c
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      inflater.inflate(R.layout.compound_view, this);
  
  }
     }
  </code></pre>
  
  <p>Now, if I use 2 of these <code>View</code> in my _activity_main.xml_:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity" &gt;
  &lt;it.moondroid.compoundview.example.CompoundView
      android:id="@+id/compoundview1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true" /&gt;
  
  &lt;it.moondroid.compoundview.example.CompoundView
      android:id="@+id/compoundview2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@id/compoundview1" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and in the Activity code I only inflate the RelativeLayout, without managing onSaveInstanceState:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  }
  </code></pre>
  
  <p>then when I write something in the 2nd <code>EditText</code> and I rotate my device, the same <code>text</code> appears in the EditText of the first custom <code>View</code>.</p>
  
  <p>Why is happening this behaviour?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I solved the issue by removing <em>android:id</em> and using <em>android:tag</em> for the <code>EditText</code> in compound_view.xml, then managing the saving of the EditText state in CompoundView class:</p>
  
  <pre><code>@Override
  protected Parcelable onSaveInstanceState() {
  
      Bundle bundle = new Bundle();
      bundle.putParcelable("instanceState", super.onSaveInstanceState());
      bundle.putString("currentEdit", mEditText.getText().toString());
      bundle.putBoolean("isFocused", mEditText.hasFocus());
      return bundle;
  
  }
  
  @Override
  protected void onRestoreInstanceState(Parcelable state) {
  
      if (state instanceof Bundle) {
          Bundle bundle = (Bundle) state;
          mEditText.setText(bundle.getString("currentEdit"));
          if (bundle.getBoolean("isFocused")) {
              mEditText.requestFocus();
          }
          super.onRestoreInstanceState(bundle.getParcelable("instanceState"));
          return;
      }
  
      super.onRestoreInstanceState(state);
  }
  </code></pre>