title: Different "visibility" values in each row in a ListView
body: <p>I have developed a very simple app that uses a custom adapter for a ListView.</p>
  
  <p>Each row has two TextViews:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
      &lt;TextView android:id="@+id/text1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
      &lt;TextView android:id="@+id/text2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:visibility="gone" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The first TextView is named "text1", and the second "text2".
  As you see, <strong>text2 is hidden (visibility="gone")</strong>.</p>
  
  <p>Also, the list has a header that only contains an EditText widget:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"&gt;
      &lt;EditText android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Each row is represented by a very simple object named "Item" that has 2 properties (text1 and text2), and its getters/setters. Also, it has a "hasText2" method that just checks if the object has the text2 property value's length > 0:</p>
  
  <pre><code>public class Item {
      private String text1;
      private String text2;
  
      public String getText1() {
          return text1;
      }
      public void setText1(String text1) {
          this.text1 = text1;
      }
      public boolean hasText2() {
          return text2.length() &gt; 0;
      }
      public String getText2() {
          return text2;
      }
      public void setText2(String text2) {
          this.text2 = text2;
      }
  }
  </code></pre>
  
  <p>Okay, I'll initialize the list with just 2 items in my main app file:</p>
  
  <pre><code>Item item1 = new Item();
  item1.setText1("Item 1");
  item1.setText2("optional 1");
  Item item2 = new Item();
  item2.setText1("Item 2");
  item2.setText2("");
  
  getListView().addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null), false, false);
  
  m_items = new ArrayList&lt;Item&gt;();
  m_adapter = new CustomListAdapter(this, R.layout.list_row, m_items);
  setListAdapter(m_adapter);
  
  m_items.add(item1);
  m_items.add(item2);
  m_adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>This is the getView method of my custom adapter (that extends ArrayAdapter):</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
          LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = vi.inflate(R.layout.list_row, null);
      }
  
      // get the two text widgets of this row layout
      TextView text1 = (TextView) convertView.findViewById(R.id.text1);
      TextView text2 = (TextView) convertView.findViewById(R.id.text2);
  
      // get the Item object of this row
      Item list_item = items.get(position);
  
      // we set the text1 property of this Item to the text1 widget
      text1.setText(list_item.getText1());
  
      // if this Item has a text2 (value length &gt; 0), then set it to the text2 widget and make it visible 
      if (list_item.hasText2()) {
          text2.setText(list_item.getText2());
          text2.setVisibility(0);
      }
  
      return convertView;
  }
  </code></pre>
  
  <p>So, what I want is to <strong>show the text2 widget only if the Item object has it defined (value's length > 0)</strong>.</p>
  
  <p>And this is the result after running the app:</p>
  
  <p><img src="https://i.stack.imgur.com/UNmdV.png" alt="enter image description here"></p>
  
  <p>That's good, it works just as I expected!! :)</p>
  
  <p>But what if I tap the EditText of the list header? (so I force to update the list):</p>
  
  <p><img src="https://i.stack.imgur.com/33OcI.png" alt="enter image description here"></p>
  
  <p>What happened here? That's impossible. The second row has no text2 defined, and Android just has taken the text2 from the first row! Why??</p>
  
  <p>The only reason I could imagine is that I cannot use rows with different visibility... but then, why Android let me do it when I just run the app? It seems to fail only when the keyboard appears (list update).</p>