title: onListItemClick for ListView not working - Android
body: <p>I'm trying to implement OnListItemClick but can't seem to get it working. There are no errors coming up, no force closes etc. Below is the code I have:</p>
  
  <pre><code>package com.odhranlynch.filmCollection;
  
  import java.io.BufferedInputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.URL;
  import java.net.URLConnection;
  import java.util.ArrayList;
  
  import org.apache.http.util.ByteArrayBuffer;
  
  import android.app.Activity;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.SQLException;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  
  public class Main extends Activity {
  /** Called when the activity is first created. */
  private final String databaseFilename = "/films.db"; //filename
  private final String url = "www.somesite.com"; //download database from here
  ArrayList&lt;FilmRecord&gt; films = new ArrayList&lt;FilmRecord&gt;();
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      DownloadFromUrl(url, databaseFilename);
  
      ListView listView = (ListView) findViewById(R.id.lstFilms);
      listView.setAdapter(new FilmItemAdapter(this, android.R.layout.simple_list_item_1, films));
  }
  
  
  protected void onListItemClick(ListView l, View v, int position, long id)
  {
      //ListItem clicked.
      Log.d("ListView", String.valueOf(l.getSelectedItemPosition()));
  }
  
  public void DownloadFromUrl(String DownloadUrl, String fileName) {  
      try {
          File root = android.os.Environment.getExternalStorageDirectory();               
  
          File dir = new File (root.getAbsolutePath() + "/Android/data/com.odhranlynch.filmcollection");
          if(dir.exists()==false) {
               dir.mkdirs();
          }
  
          URL url = new URL(DownloadUrl); //you can write here any link
          File file = new File(dir, fileName);
  
          long startTime = System.currentTimeMillis();
          Log.d("DownloadManager", "download begining");
          Log.d("DownloadManager", "download url:" + url);
          Log.d("DownloadManager", "downloaded file name:" + fileName);
  
          /* Open a connection to that URL. */
          URLConnection ucon = url.openConnection();
  
          /*
           * Define InputStreams to read from the URLConnection.
           */
          InputStream is = ucon.getInputStream();
          BufferedInputStream bis = new BufferedInputStream(is);
  
          /*
           * Read bytes to the Buffer until there is nothing more to read(-1).
           */
          ByteArrayBuffer baf = new ByteArrayBuffer(5000);
          int current = 0;
          while ((current = bis.read()) != -1) {
             baf.append((byte) current);
          }
  
  
          /* Convert the Bytes read to a String. */
          FileOutputStream fos = new FileOutputStream(file);
          fos.write(baf.toByteArray());
          fos.flush();
          fos.close();
          Log.d("DownloadManager", "download ready in" + ((System.currentTimeMillis() - startTime) / 1000) + " sec");
  
          //Download completed, run populateFields method.
          populateFields();
  
  } catch (IOException e) {
      Log.d("DownloadManager", "Error: " + e);
      }
  }
  
  public class FilmItemAdapter extends ArrayAdapter&lt;FilmRecord&gt; {
      private ArrayList&lt;FilmRecord&gt; films;
  
      public FilmItemAdapter(Context context, int textViewResourceId, ArrayList&lt;FilmRecord&gt; films) {
          super(context, textViewResourceId, films);
          this.films = films;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View v = convertView;
          if (v == null) {
              LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              v = vi.inflate(R.layout.listitem, null);
          }
  
          FilmRecord film = films.get(position);
          if (film != null) {
              TextView filmTitle = (TextView) v.findViewById(R.id.username);
              TextView filmShowingDate = (TextView) v.findViewById(R.id.email);
  
              if (filmTitle != null) {
                  filmTitle.setText(film.filmTitle);
              }
  
              if(filmShowingDate != null) {
                  filmShowingDate.setText("Showing on " + film.filmShowingDate );
              }
          }
          return v;
      }
  }
  
  public class FilmRecord {
      public String filmTitle;
      public String filmShowingDate;
  
      public FilmRecord(String username, String email) {
          this.filmTitle = username;
          this.filmShowingDate = email;
      }
  }
  
  public void populateFields() {
      //Populate the views with database content.
  
  
      DataBaseHelper myDbHelper = new DataBaseHelper(this);;
      myDbHelper = new DataBaseHelper(this);
  
      //Load "productDatabase" database (see assets to left).
      {
          try {
              myDbHelper.createDataBase();} 
          catch (IOException ioe) {
              throw new Error("Unable to create database");}
  
          try {
              myDbHelper.openDataBase();}
          catch(SQLException sqle){
              throw sqle;}
      }
  
    //---Get all records from database---
      myDbHelper.openDataBase();
      Cursor cursorPosition = myDbHelper.getAllTitles();
  
  
      if (cursorPosition.moveToFirst())
      {
      do {
      AddRecordToArray(cursorPosition);
      } while (cursorPosition.moveToNext());
      }
      myDbHelper.close();
      }
  
      public void AddRecordToArray(Cursor cursorPosition)
      {
          //Add new record to array (which gets data from database using cursorPosition (for current row) and .getstring( for column number).
          FilmRecord film1 = new FilmRecord(cursorPosition.getString(1), cursorPosition.getString(4));
          films.add(film1);
      }
  }
  </code></pre>
  
  <p>I would be really appreciative if someone would be kind enough to help me out on this one :)</p>