Android : how can create alphabet sound onclick of image button

on Tuesday, August 5, 2014


I am developing a kids application. I am using View flipper to slide the images and add two button nest and previousI want when i press A button play sound A and when i press apple button play sound Apple . I have all the image take in array type int and put into drawable folder.i want to play sound according to image alphabet.Please tell me how can create a kid application with image and sound . i am trying something but crash



private ViewFlipper viewFlipper;
private ImageSwitcher imageSwitcher;
Button next,pre;
int[]sound;
MediaPlayer mp;


protected void onCreate(Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.image);

sound= new int[]{R.raw.pack1s1,R.raw.pack1s2,R.raw.pack1s3,R.raw.pack1s4};
mp = MediaPlayer.create(getApplicationContext(), R.raw.pack1s1);

int Images[]={R.drawable.pack1d1,R.drawable.pack1d2,R.drawable.pack1d3,R.drawable.pack1d4,R.drawable.pack1d5,R.drawable.pack1d6,
R.drawable.pack1d7,R.drawable.pack1d8,R.drawable.pack1d9,R.drawable.pack1d10,R.drawable.pack1d11,R.drawable.pack1d12,
R.drawable.pack1d13,R.drawable.pack1d14,R.drawable.pack1d15,R.drawable.pack1d16,
R.drawable.pack1d17,R.drawable.pack1d18,R.drawable.pack1d19,R.drawable.pack1d20,R.drawable.pack1d21,R.drawable.pack1d22,
R.drawable.pack1d23,R.drawable.pack1d24,R.drawable.pack1d25,R.drawable.pack1d26};

viewFlipper = (ViewFlipper) findViewById(R.id.flipper);
next=(Button)findViewById(R.id.button1);
pre=(Button)findViewById(R.id.button2);
pre.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
viewFlipper.showPrevious();

}
});
next.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
viewFlipper.showNext();
}
});

for(int i=0;i<Images.length;i++)
{
setFlipperImage(Images[i]);
}


}



private void setFlipperImage(int res)
{
Log.i("Set Filpper Called", res+"");
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(res);
viewFlipper.addView(image);
}


}


0 comments:

Post a Comment