title: ListView inside a Fragment used in a ViewPager does not behave like expected
body: <p>I am having an issue with the items in this list view. Normal behaviour is that when user taps in one item, the background color changes to orange. This is not happening to my app, and I can't figure out why.</p>
  
  <p>The main.xml has just a:</p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager
          android:id="@+id/pager"
          android:layout_width="fill_parent"
          android:layout_height="0dp"
          android:layout_weight="1" /&gt;
  </code></pre>
  
  <p>The fragment's xml has only a:</p>
  
  <pre><code>&lt;ListView
          android:id="@android:id/list"
          style="@style/MyListView"
          android:layout_width="match_parent"
          android:layout_height="match_parent" &gt;
      &lt;/ListView&gt;
  </code></pre>
  
  <p>The view that I inflate inside the listView item is:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:clickable="true"
      android:focusable="true"
      android:focusableInTouchMode="true" &gt;
  
      &lt;ImageView
          android:id="@+id/imageView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:clickable="false"
          android:focusable="false"
          android:focusableInTouchMode="false"
          android:src="@drawable/ic_launcher" /&gt;
  
      &lt;TextView
          android:id="@+id/textViewName"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_marginLeft="5dp"
          android:layout_toRightOf="@+id/imageView1"
          android:clickable="false"
          android:focusable="false"
          android:focusableInTouchMode="false"
          android:text=""
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/imageView1"
          android:layout_alignLeft="@+id/textViewName"
          android:clickable="false"
          android:focusable="false"
          android:focusableInTouchMode="false"
          android:text=""
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;ImageView
          android:id="@+id/imageView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_marginRight="10dp"
          android:clickable="false"
          android:focusable="false"
          android:focusableInTouchMode="false"
          android:src="@drawable/bottom_arrow" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The style I defined for the ListView is:</p>
  
  <pre><code>&lt;style name="MyListView" parent="@android:style/Widget.ListView.White"&gt;
          &lt;item name="android:listSelector"&gt;@drawable/list_subject_selector&lt;/item&gt;
          &lt;item name="android:cacheColorHint"&gt;@android:color/transparent&lt;/item&gt;
          &lt;item name="android:background"&gt;@drawable/list_subject_selector&lt;/item&gt;
      &lt;/style&gt;
  </code></pre>
  
  <p>And the list_subject_selector drawable is:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;!-- touch down --&gt;
      &lt;item android:drawable="@drawable/list_subject_focused" android:state_pressed="true"/&gt;
      &lt;!-- selected --&gt;
      &lt;item android:drawable="@drawable/list_subject_unfocused" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>I have no idea why this is happening... I am testing with Android ICS.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks everyone,
  Felipe</p>
  
  <p><strong>UPDATE 1</strong>
  This is the ListFragment code:</p>
  
  <pre><code>public class MyFragment extends ListFragment {
      private ListAdaptor adapter;
      private InternalDB db;
      Context mContext;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          mContext = getActivity();
          db = new InternalDB(getActivity());
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          ArrayList&lt;EventVO&gt; listVO = db.getSummaryEvents(true);
          adapter = new ListAdaptor(mContext, R.layout.event_inflate, listVO);
          setListAdapter(adapter);            
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          LinearLayout rl = (LinearLayout) inflater.inflate(R.layout.general_list, container, false);
          return rl;
      }
  
      private class ListAdaptor extends ArrayAdapter&lt;EventVO&gt; {
          private ArrayList&lt;EventVO&gt; listVO;
  
          public ListAdaptor(Context context, int textViewResourceId, ArrayList&lt;EventVO&gt; items) {
              super(context, textViewResourceId, items);
              this.listVO = items;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              View v = convertView;
              if (v == null) {
                  v = ViewGroup.inflate(getContext(), R.layout.event_inflate, null);
              }
              final EventVO o = listVO.get(position);
              TextView fullName = (TextView) v.findViewById(R.id.textViewName);
              fullName.setText(o.getUserName());
  
              //removed part of the code for brevity
  
              v.setOnClickListener(new OnClickListener() {
                  @Override
                  public void onClick(View arg0) {
                      Intent i = new Intent(mContext, EventDetailsActivity.class);
                      i.putExtra("USER_ID", o.getUserId());                       
                      startActivity(i);
                  }
              });
              return v;
          }
      }
  }
  </code></pre>
  
  <p><strong>UPDATE 2</strong>
  It now works! That was very annoying. This I did to make it work:</p>
  
  <p>The xml file that I was using to inflate had:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:clickable="true"
          android:focusable="true"
          android:focusableInTouchMode="true" &gt;
  </code></pre>
  
  <p>I changed to:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"&gt;
  </code></pre>
  
  <p>But, what I think that really made the change was this:
  Inside the onActivityCreated()</p>
  
  <pre><code>list = getListView();
          list.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
                  ListAdaptor la = (ListAdaptor)arg0.getAdapter();
                  EventVO vo = la.getItem(arg2);
                  Intent i = new Intent(mContext, EventDetailsActivity.class);
                  i.putExtra("USER_ID", vo.getUserId());
                  i.putExtra("IS_BORROWED", true);
                  startActivity(i);
              }
  </code></pre>
  
  <p>The important is the line <em>list = getListView();</em>
  I wasn't getting the ListView through this piece of code. I was getting the listView at the onCreateView() method, with a findViewById. I suppose that I was losing the link with the real ListView object.</p>
  
  <p>Thanks to everyone who helped me! :)</p>
  
  <p>Felipe
              });</p>