title: How to play sound while clicking on GridView items?
body: <p>I have implemented a <code>GridView</code> and want different sound on clicking each <code>GridView</code> item. So far I have implemented this code but I'm confused how to implement <code>onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id)</code></p>
  
  <p>My code for main activity is:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
      MediaPlayer mp = null;
      String c1, c2 = "c2", c3 = "c3", c4 = "c4", c5 = "c5";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      GridView gridview = (GridView) findViewById(R.id.gridview);
      gridview.setAdapter(new ImageAdapter(this));
  
      gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int
  position, long id) {
              managerOfSound(c1);
              managerOfSound(c2);
              managerOfSound(c3);
              managerOfSound(c4);
              managerOfSound(c5);
          }
          });
      }
  
  protected void managerOfSound(String theText) {
      if (mp != null) {
          mp.reset();
          mp.release();
      }
      if (position)
          mp = MediaPlayer.create(this, R.raw.c1);
      else if (theText == c2)
          mp = MediaPlayer.create(this, R.raw.c2);
      else if (theText == c3)
          mp = MediaPlayer.create(this, R.raw.c3);
      else if (theText == c4)
          mp = MediaPlayer.create(this, R.raw.c4);
      else
          mp = MediaPlayer.create(this, R.raw.c5);
      mp.start();
     }
  
  
  }
  </code></pre>
  
  <p>My code for GridView Adapter is </p>
  
  <pre><code>    public class ImageAdapter extends BaseAdapter {
      private Context mContext;
  
      public ImageAdapter(Context c) {
      mContext = c;
   }
  
    public int getCount() {
      return mThumbIds.length;
     }
  
     public Object getItem(int position) {
        return null;
     }
  
     public long getItemId(int position) {
      return 0;
    }
  
     // create a new ImageView for each item referenced by the Adapter
      public View getView(int position, View convertView, ViewGroup parent) {
      ImageView imageView;
      if (convertView == null) {
          // if it's not recycled, initialize some attributes
          imageView = new ImageView(mContext);
          imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
          imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
          imageView.setPadding(4, 4, 4, 4);
        } else {
          imageView = (ImageView) convertView;
      }
  
      imageView.setImageResource(mThumbIds[position]);
      return imageView;
     }
     // references to our images
     private Integer[] mThumbIds = {
          R.drawable.cc1, R.drawable.cc2, R.drawable.cc3,
          R.drawable.cc4, R.drawable.cc5, R.drawable.cc6,
          R.drawable.cc7, R.drawable.cc8, R.drawable.cc9,
          R.drawable.cc10, R.drawable.cc11, R.drawable.cc12,
          R.drawable.cc13,
          R.drawable.cc14, R.drawable.cc15, R.drawable.cc16,
          R.drawable.cc17, R.drawable.cc18, R.drawable.cc19,
          R.drawable.cc20,
          R.drawable.cc21, R.drawable.cc22, R.drawable.cc23,
          R.drawable.cc24, R.drawable.cc25, R.drawable.cc26,
          R.drawable.cc27, R.drawable.cc28, R.drawable.cc29,
          R.drawable.cc30;
      };
     }
  </code></pre>
  
  <p>And my code for Layout is </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;GridView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/gridview"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:columnWidth="90dp"
   android:numColumns="auto_fit"
   android:verticalSpacing="10dp"
   android:horizontalSpacing="10dp"
   android:stretchMode="columnWidth"
   android:gravity="center"
    /&gt;
  </code></pre>