我尝试在很多地方搜索这个,但找不到答案。我正在制作一个带有一组带有字母的图像按钮的应用程序。我希望能够单击字母A,并听到声音文件A。如果单击字母B,我想听到声音文件B。到目前为止,我只有字母A和B,以及声音文件A和B。当我运行我的代码,我只能听到按钮 A 的声音,当我按下字母 B 时,什么也没有发生。这是我的代码:
package com.android.nishad.learn.hindi;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class AlphabetActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alphabet);
ImageButton btn = (ImageButton)findViewById(R.id.imageButton1);
btn.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
mp = MediaPlayer.create(this, R.raw.lettera);
mp.start();
while (mp.isPlaying()) {
// do nothing
};
mp.release();
}
public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alphabet);
ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
btn2.setOnClickListener(this);
}
public void onClick1(View v) {
// TODO Auto-generated method stub
mp = MediaPlayer.create(this, R.raw.letterb);
mp.start();
while (mp.isPlaying()) {
// do nothing
};
mp.release();
}
};