title: In list fragment clicking first time on list item do not changes the background of item
body: <p>I am using list fragment to display list of item and i want that in such a way that, whenever the item is clicked its background should change and is changing too but when first time any item is clicked no change is their in the background of that item.Please help me. my code is here</p>
  
  <p>Fragment class:-</p>
  
  <pre><code>public class Categoryfragment extends ListFragment 
  
   {
     DBhelper dh;
    Cursor cursor;
        @Override
      public void onCreate(Bundle savedInstanceState)
  {       
  // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
        dh = new DBhelper(getActivity()); 
    refreshadpater();
  }
    @Override
      public void onActivityCreated(Bundle savedInstanceState)
       {
      super.onActivityCreated(savedInstanceState);
       }
  
      public void refreshadpater()
       {
            dh = new DBhelper(getActivity());
            cursor= dh.fetchAllcategories();
        String []columns= {"category_name"};
        int []textid = {R.id.text1};
         SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.list,    cursor, columns, textid);
          setListAdapter(adapter);
  
   }
  
  
      @Override
      public void onListItemClick(ListView l, View v, int position, long id)
       {  
  
         getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
         LinearLayout ii=(LinearLayout)getActivity().findViewById(R.id.lin);
           ii.setBackgroundResource(R.drawable.item_selector);
  
              int id1 =(int)id ;
  
        Subcategoryfragment fragment = (Subcategoryfragment)   getFragmentManager().findFragmentById(R.id.secondFragment);
        TextView tv = (TextView)getActivity().findViewById(R.id.sub);
  
        tv.setText("Sub-cat");
        if (fragment != null &amp;&amp; fragment.isInLayout())
        {              
            fragment.refreshadpater1(id1);
  </code></pre>
  
  <p>//            ii.setBackgroundResource(R.drawable.item_selector);</p>
  
  <pre><code>      } 
       }
  </code></pre>
  
  <p>}</p>
  
  <p>list.xml</p>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
      android:id="@+id/lin"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:background="@drawable/item_selector"&gt;
  
       &lt;TextView android:id="@+id/text1"
  
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:layout_marginTop="10dp"
         android:layout_marginLeft="10dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:minHeight="?android:attr/listPreferredItemHeight"
  
         /&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>  item_selector.xml
  
  
      &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  
  
      &lt;item android:state_activated="true" &gt;
      &lt;shape &gt;
          &lt;solid android:color="#FF666666" /&gt;
      &lt;/shape&gt;
  &lt;/item&gt;
  &lt;item android:state_pressed="true"&gt;
        &lt;shape&gt;
          &lt;solid android:color="#FF666666" /&gt;
      &lt;/shape&gt;
      &lt;/item&gt;
  
  
  &lt;/selector&gt;
  </code></pre>