title: Using multiple onItemClick's in one activity.. "Duplicate method" error?
body: <p>I've made a list of artists, that once clicked bring up a list of albums. The idea is that once an album is clicked, the list of songs comes up. </p>
  
  <p>Unfortunately, because there are two listviews being generated in this activity, the second 'onItemClick' method gets flagged in eclipse as 'duplicate'. Does anyone have any idea how to fix this?</p>
  
  <p>Here is the main activity code:</p>
  
  <pre><code>package music.library;
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  
  public class MusicLibrary extends Activity implements OnItemClickListener {
    Cursor cursor;
    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      String[] columns = { 
              MediaStore.Audio.Artists._ID,
              MediaStore.Audio.Artists.ARTIST };
  
      cursor = managedQuery(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
          columns, null, null, null);
  
      ListView listView = (ListView) findViewById(R.id.listView);
      listView.setOnItemClickListener(this);
      String[] displayFields = new String[] { MediaStore.Audio.Artists.ARTIST };
      int[] displayViews = new int[] { R.id.artistItem };
      SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
          R.layout.artist_item, cursor, displayFields, displayViews);
      listView.setAdapter(adapter);
  
    }
  
  
    @SuppressWarnings("deprecation")
  public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
      if (cursor.moveToPosition(position)) {
  
        String[] columns = {
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ALBUM,
       };
  
        String where = android.provider.MediaStore.Audio.Media.ARTIST
            + "=?";
  
        String whereVal[] = { cursor.getString(cursor
            .getColumnIndex(MediaStore.Audio.Albums.ARTIST)) };
  
        String orderBy = android.provider.MediaStore.Audio.Media._ID;
  
        cursor = managedQuery(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, columns,
            where, whereVal, orderBy);
  
        ListView listView = (ListView) findViewById(R.id.listView);
        String[] displayFields = new String[] { MediaStore.Audio.Media.ALBUM };
        int[] displayViews = new int[] { R.id.albumItem };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.album_item, cursor, displayFields, displayViews);
        listView.setAdapter(adapter);
  
      }
    }
  
  
    @SuppressWarnings("deprecation")
  public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
          if (cursor.moveToPosition(position)) {
  
              String[] columns = { 
                  MediaStore.Audio.Media._ID,
                  MediaStore.Audio.Media.DISPLAY_NAME,
              };
  
              String where = MediaStore.Audio.Media.ALBUM
                  + "=?";
  
              String whereVal[] = { cursor.getString(cursor
                  .getColumnIndex(MediaStore.Audio.Albums.ALBUM)) };
  
              String orderBy = MediaStore.Audio.Media._ID;
  
              cursor = managedQuery(
                  MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, columns,
                  where, whereVal, orderBy);
  
              ListView listView = (ListView) findViewById(R.id.listView);
              String[] displayFields = 
                      new String[] { MediaStore.Audio.Media.DISPLAY_NAME };
              int[] displayViews = new int[] { R.id.songItem };
              SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                      R.layout.song_item, cursor, displayFields, displayViews);
                  listView.setAdapter(adapter);
  
      }
    }
  
  }
  </code></pre>
  
  <p>Thanks for your help.</p>
  
  <p>----Edit----</p>
  
  <p>Thanks for the answers guys. Whilst all of the answers were great, I've chosen dymmeh's answer as my 'accepted' answer, as separating the views into different activities seems to make the most sense (even if this is not what I'd stated I was looking for in the initial question).</p>
  
  <p>I ended up creating the following:</p>
  
  <p>First class, showing artists:</p>
  
  <pre><code>package music.library;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  
  public class MusicLibrary extends Activity implements OnItemClickListener {
    Cursor cursor;
    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      String[] columns = { 
              MediaStore.Audio.Artists._ID,
              MediaStore.Audio.Artists.ARTIST 
              };
  
      cursor = managedQuery(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
          columns, null, null, null);
  
      ListView listView = (ListView) findViewById(R.id.listView);
      listView.setOnItemClickListener(this);
      String[] displayFields = new String[] { MediaStore.Audio.Artists.ARTIST };
      int[] displayViews = new int[] { R.id.artistItem };
      SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
          R.layout.artist_item, cursor, displayFields, displayViews);
      listView.setAdapter(adapter); }
  
      public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
          if (cursor.moveToPosition(position)) {
  
              String where = android.provider.MediaStore.Audio.Media.ARTIST
            + "=?";
  
              String whereVal[] = { cursor.getString(cursor
            .getColumnIndex(MediaStore.Audio.Albums.ARTIST)) };
  
      Intent intent = new Intent(MusicLibrary.this, AlbumSelection.class);
      intent.putExtra("where", where);
      intent.putExtra("whereVal", whereVal);
      startActivity(intent);
  
          }
       }
    } 
  </code></pre>
  
  <p>Second class, showing albums:</p>
  
  <pre><code>package music.library;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  
  public class AlbumSelection extends Activity implements OnItemClickListener {
    Cursor cursor;
    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Bundle extras = getIntent().getExtras();
      String where = extras.getString("where");
      String[] whereVal = extras.getStringArray("whereVal");
  
      String[] columns = {
              MediaStore.Audio.Media._ID,
              MediaStore.Audio.Media.ALBUM,
         };
  
          String orderBy = android.provider.MediaStore.Audio.Media._ID;
  
      cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
          columns, where, whereVal, orderBy);
  
      ListView listView = (ListView) findViewById(R.id.listView);
      listView.setOnItemClickListener(this);
      String[] displayFields = new String[] { MediaStore.Audio.Media.ALBUM };
      int[] displayViews = new int[] { R.id.albumItem };
      SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
          R.layout.album_item, cursor, displayFields, displayViews);
      listView.setAdapter(adapter); }
  
    public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
        if (cursor.moveToPosition(position)) {
  
          String where = android.provider.MediaStore.Audio.Media.ALBUM
          + "=?";
  
          String whereVal[] = { cursor.getString(cursor
          .getColumnIndex(MediaStore.Audio.Albums.ALBUM)) };
  
    Intent intent = new Intent(AlbumSelection.this, SongSelection.class);
    intent.putExtra("where", where);
    intent.putExtra("whereVal", whereVal);
    startActivity(intent);
  
         }    
      }
    } 
  </code></pre>
  
  <p>Third class, showing songs:</p>
  
  <pre><code>package music.library;
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  
  public class SongSelection extends Activity implements OnItemClickListener {
      Cursor cursor;
        @SuppressWarnings("deprecation")
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          Bundle extras = getIntent().getExtras();
          String where = extras.getString("where");
          String[] whereVal = extras.getStringArray("whereVal");
  
          String[] columns = {
                  MediaStore.Audio.Media.DATA,
                  MediaStore.Audio.Media._ID,
                  MediaStore.Audio.Media.TITLE,
                  MediaStore.Audio.Media.DISPLAY_NAME,
                  MediaStore.Audio.Media.MIME_TYPE,
             };
  
              String orderBy = android.provider.MediaStore.Audio.Media.TITLE;
  
          cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
              columns, where, whereVal, orderBy);
  
          ListView listView = (ListView) findViewById(R.id.listView);
          listView.setOnItemClickListener(this);
          String[] displayFields = new String[] { MediaStore.Audio.Media.TITLE };
          int[] displayViews = new int[] { R.id.songItem };
          SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
              R.layout.song_item, cursor, displayFields, displayViews);
          listView.setAdapter(adapter); }
  
          public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
              if (cursor.moveToPosition(position)) {
  
          /*Intent intent = new Intent(AlbumSelection.this, SongSelection.class);
          intent.putExtra("ARTIST", artist);
          startActivity(intent);
  */
             }    
          }
        } 
  </code></pre>
  
  <p>And it's all working sweet.</p>
  
  <p>Thanks heaps for all the responses. I'd be keen to hear any feedback on how this code might be tidied / made more efficient.</p>
  
  <p>Thanks again.</p>