title: Android/ListView : Select first item after loading datas
body: <p><strong>EDIT</strong>
  I must tell you that my ListView is populate by an AsyncTask.</p>
  
  <p>The code below works fine when I do in onPostExecute method :</p>
  
  <pre><code>synchronized (mListView) {
              if(mFeeds==null || mFeeds.size()==0){
                  Utils.Log("mFeeds empty");
                  _this.setListShown(false);
              }else{
                  Utils.Log("mFeeds Full");
                  _this.setListShown(true);
                  mListView.setAdapter(new ListFeedsAdapter(mActivity,mFeeds));
                  mListView.notifyAll();
  
                  NewsFeedsDetailViewPagerFragment fragment = (NewsFeedsDetailViewPagerFragment) getFragmentManager()
                          .findFragmentById(R.id.feeddetailViewPagerFragment);
  
                  if(fragment!=null){
                      mListView.performItemClick(null, 0, mListView.getFirstVisiblePosition());
  
                  }
              }
  
          }
  </code></pre>
  
  <p>The item is clicked and my detail view is populate...</p>
  
  <p>I try to change my Fragment to a ListFragment but nothing changed...</p>
  
  <p><strong>EDIT END</strong></p>
  
  <p>For my application, I created an UI (for tablet) with ListView at left screen and a detail view at the right.
  I would like to automatically select the first item after loading datas, and view the detail.</p>
  
  <p>I am able to do this by calling <code>mListView.performItemClick(null, 0, mListView.getFirstVisiblePosition());</code> and </p>
  
  <pre><code>mListView.setOnItemClickListener(new OnItemClickListener() {
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
              long arg3) {
      // TODO Auto-generated method stub
  
      NewsFeedsDetailViewPagerFragment fragment = (NewsFeedsDetailViewPagerFragment)
              getFragmentManager().findFragmentById(R.id.feeddetailViewPagerFragment);
      if(fragment!=null){
          fragment.setFeedDetail(mFeeds, arg2);
      }
  });
  </code></pre>
  
  <p>Now, what I want to do is to highlight the first item like Gmail application for tablet.
  I use a selector background on each row like : </p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:drawable="@drawable/selected_item_background" android:state_activated="true"/&gt;
      &lt;item android:drawable="@drawable/pressed_item_background" android:state_activated="false" android:state_pressed="true"/&gt;
      &lt;item android:drawable="@drawable/pressed_item_background" android:state_focused="true"/&gt;
      &lt;item android:drawable="@drawable/unselected_item_background"/&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>When I use <code>mListView.getChildAt(arg2).setActivated(true);</code> in the onItemClick listener, I have a NullPointerException because <code>mListView.getChildAt(arg2)</code> is null, only if I keep the perforItemClick. If I just comment this line, and click on a row, this row is highlight as in Gmail application.</p>
  
  <p>Can you help me and tell me what I'm doing wrong ?</p>
  
  <p>Thank in advance</p>