title: Adding ItemListener in Android ListView
body: <p>I've a swive view along with 4 tabs which displays in my first UI. I've added ListView for each Tabs. But OnItemClickListener is not working for ListFragment. My class is extended from ListFragment and implements OnItemClickListener. What i wanted to do is that when i select a item from the list, i've to display the Toast which displays the name of item that i've selected. But its not working for me. No error occurs but not getting the things done. Can anyone help me for this. My complete code for this is below:</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.ListFragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.Toast;
  
  public class TUFragment extends ListFragment implements OnItemClickListener {
  
  ListView list;
  View rootView;
  
  final String[] courses = new String[] { "BIM", "BBA", "BBS", "BSc-CSIT",
          "BSc-IT", "BHM", "BTTM", "MBA", "MBS", "MSc-IT", "MTTM" };
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      rootView = inflater.inflate(R.layout.fragment_tu, container, false);
  
      list = (ListView) rootView.findViewById(android.R.id.list);
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(),
              android.R.layout.simple_list_item_1, courses);
      list.setAdapter(adapter);
  
      list.setOnItemClickListener(this);
  
      return rootView;
  }
  
  @Override
  public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
      Toast.makeText(this.getActivity(), "You have Selected: " + courses[arg2],
              Toast.LENGTH_LONG).show();
  }
  }
  </code></pre>
  
  <p>Thankx in advance</p>