The below code I made works fine when I type the animal-name and it plays the animal sound but how can I make it simpler for 200 sound files. like getting the string from edittext and searching the file from raw folder and play. If entered text is "dog" it should play "dog.mp3"
editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
{
String name = editText.getText().toString();
if(name.contentEquals("cow")){
mp = MediaPlayer.create(Selection1Page1.this, R.raw.cow);
mp.start();
}
if(name.contentEquals("bat")){
mp = MediaPlayer.create(Selection1Page1.this, R.raw.bat);
mp.start();
}
if(name.contentEquals("cat")){
mp = MediaPlayer.create(Selection1Page1.this, R.raw.cat);
mp.start();
}
}
}