play sound while clicking images android java

Pico

New Member
I'm new to android and trying to make the application and then finding a problem to play the sound when I click on the picture drawn in the Aray, which I want to do is play a different sound when you click a different picture. I hope I find the solution of your answers here, thank you ..this my java code\[code\]public class gorendis extends Activity implements MediaPlayer.OnCompletionListener{private ImageView play;private ImageView a2;private MediaPlayer mp;@Overridepublic void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.huruf); play=(ImageView)findViewById(R.id.a1); a2=(ImageView)findViewById(R.id.a2); //gambar=(ImageButton)findViewById(R.id.gambar); //gambar.setImageResource(R.drawable.a1); play.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { play(); } }); a2.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { play(); } }); setup();}@Overridepublic void onDestroy() { super.onDestroy();}public void onCompletion(MediaPlayer mp) { stop();}private void stop() { // TODO Auto-generated method stub}private void play() { mp.start(); play.setEnabled(true);}private void loadClip() { try { mp=MediaPlayer.create(this, R.raw.doajodoh); mp.setOnCompletionListener(this); } catch (Throwable t) { goBlooey(t); }}private void setup() { loadClip(); play.setEnabled(true);}private void goBlooey(Throwable t) { AlertDialog.Builder builder=new AlertDialog.Builder(this); builder .setTitle("Exception!") .setMessage(t.toString()) .setPositiveButton("OK", null) .show();}}\[/code\]"here I try to add my layout file but it always fails when it is needed to provide appropriate answers I will write later"Main Layout\[code\]<?xml version="1.0" encoding="utf-8"?><ScrollView> <LinearLayout> <ImageView android:id="@+id/play" android:layout_width="wrap_content" android:layout_height="53px" android:background="@android:color/transparent" android:scaleType="fitCenter" android:src="http://stackoverflow.com/questions/11256004/@drawable/a1" > </ImageView> <ImageView android:id="@+id/a2" android:layout_width="wrap_content" android:layout_height="53px" android:background="@android:color/transparent" android:scaleType="fitCenter" android:src="http://stackoverflow.com/questions/11256004/@drawable/a2" > </ImageView> </LinearLayout></ScrollView>\[/code\]
 
Back
Top