title: Android - Change visibility of sub-layout on listview item click
body: <p>I'd like to change the visibility of a sub-layout called <code>eventInformations</code> in my listview adapter when I'm clicking on the corresponding item.</p>
  
  <p>Here's my XML :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:paddingTop="@dimen/list_view_padding_top"
      android:paddingBottom="@dimen/list_view_padding_bottom"
      android:paddingRight="@dimen/list_view_padding_right"
      android:paddingLeft="@dimen/list_view_padding_left"&gt;
  
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/eventInformations"
          android:visibility="gone"
          android:id="@+id/eventPopup"&gt;
  
          &lt;View
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.5"&gt;
          &lt;/View&gt;
  
          &lt;Button
              android:layout_width="0dp"
              android:layout_weight="0.5"
              android:layout_height="wrap_content"
              android:id="@+id/eventActionBtn"
              android:text="@string/planning_action_register"
              /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And my <code>ListView</code> :</p>
  
  <pre><code>&lt;ListView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/eventList"
          android:layout_gravity="center"
          android:descendantFocusability="blocksDescendants" /&gt;
  </code></pre>
  
  <p>And here's my <code>OnClick</code> event handler :</p>
  
  <pre><code>eventListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          LinearLayout eventPopup = (LinearLayout)parent.getAdapter().getView(position, view, parent).findViewById(R.id.eventPopup);
          if (eventPopup.getVisibility() == View.VISIBLE)
              eventPopup.setVisibility(View.GONE);
          else
              eventPopup.setVisibility(View.VISIBLE);
      }
  });
  </code></pre>
  
  <p>It is working somewhat properly, but I'm having 2 issues :</p>
  
  <ul>
  <li>When the sub-layout is displayed, I cannot click back on the listview
  item in order to hide it.</li>
  <li>When I scroll down the listview, the selected item changes randomly...</li>
  </ul>
  
  <p>I can't seem to find why it's working that way.</p>
  
  <p>Thanks.</p>