android - One button random sounds -


i have 1 simple app 1 button. when push it, play 1 sound(btn001). play random sounds raw folder. have there 47 soundfiles named btn001 btn047. there simple way modify code make work. know there alot same questions on web. i've tryed of them have found. i'ts frustrating have'nt got work. here code:

 import android.media.mediaplayer;     import android.os.bundle;     import android.app.activity;     import android.view.menu;     import android.view.view;     import android.widget.button;      public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          button pushme = (button) findviewbyid(r.id.button1);         final mediaplayer cheer = mediaplayer.create(mainactivity.this, r.raw.btn001);          pushme.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 cheer.start();             ;             };}          );             }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      } 

create list add sounds , play random sound list. random index (int)(math.random()*47)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -