これは私が現時点で持っているコードです。同じボタンから別の音が出力されます
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthbound);
int charNo = (Integer)getIntent().getExtras().get(EXTRA_CHARNO);
Earthbound character = Earthbound.chars[charNo];
ImageView photo = (ImageView) findViewById(R.id.photo);
photo.setImageResource(character.getImageResourceId());
photo.setContentDescription(character.getName());
TextView name = (TextView) findViewById(R.id.name);
name.setText(character.getName());
TextView desc = (TextView) findViewById(R.id.desc);
desc.setText(character.getDesc());
Button voice_btn = (Button)this.findViewById(R.id.voice_btn);
voice_btn.setContentDescription(character.getName());
final MediaPlayer mp = MediaPlayer.create(this, R.raw.snd_se_narration_characall_Ness);
final MediaPlayer mmp = MediaPlayer.create(this, R.raw.snd_se_narration_characall_Lucas);
voice_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
mp.start();
mmp.start();
}
});
私は基本的に2つのアクティビティ、ユーザーがリスト表示オプション「地縛」、文字を一覧表示し、Javaクラス、および文字の生物を表示する活動を選択することができるということで最初のものを持っています。 2番目のアクティビティには1つのボタン、がありますが、このボタンはユーザーが選択した文字に応じて音色を変更します。これは私が立ち往生している場所です。
これは、Javaクラスを助けている場合:
private String name;
private String desc;
private int imageResourceId;
private int voiceId;
public Earthbound(String name, String desc, int imageResourceId, int voice){
this.name = name;
this.desc = desc;
this.imageResourceId = imageResourceId;
this.voiceId = voiceId;
}
public static final Earthbound[] chars = {
new Earthbound("Ness", "Ness is the silent main protagonist of EarthBound (Mother 2 in Japan), " +
"and is analogous to Ninten and Lucas in their respective games. He greatly enjoys baseball; " +
"not only are most of his weapons various types of baseball bats, " +
"but he can also equip several baseball caps. ", R.drawable.ness, R.raw.snd_se_narration_characall_Ness),
new Earthbound("Lucas", "Lucas is the central character of Mother 3, out of seven main characters total. " +
"(Lucas, Kumatora, Duster, Boney, Claus, Flint, and Salsa). He is from Tazmily Village. " +
"He is the gentle twin of Claus. ", R.drawable.lucas, R.raw.snd_se_narration_characall_Lucas),
};
public String getName() {
return name;
}
public String getDesc() {
return desc;
}
public int getImageResourceId() {
return imageResourceId;
}
@Override
public String toString() {
return this.name;
}
public int getVoiceId() {
return voiceId;
}
なぜ "JavaScriptの" タグ?あなたの質問にJSの他の言及はないので、私はタグを削除するつもりです。 – nnnnnn