java - Project running slow -


i'm developing application interested in guitar chords in android studio. there 2 spinners choose chord , there imageview show chord diagram on screen. when user select chord diagram appears on screen , plays. unfortunately works slow. how can make faster? here's java class

public class chords extends actionbaractivity implements adapterview.onitemselectedlistener {      string[] notes = {"a", "b", "c","c#","d", "e", "f","f#", "g"};     string[] mode = {"m", "m7", "5", " ", "7m", "dim", "aug", "sus2"};     spinner sp;     spinner spinner2;     textview textview;     textview t;     textview t2;     mediaplayer mysound,mysound2,mysound3,mysound4,mysound5,mysound6,mysound7;     private static imageview imgview;     int[] images = {r.drawable.aminor,r.drawable.eminor,r.drawable.a_major,r.drawable.cmajor,r.drawable.gmajor,r.drawable.dminor,r.drawable.bminor};     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         requestwindowfeature(window.feature_no_title);         setcontentview(r.layout.chords_screen);         textview = (textview) findviewbyid(r.id.textview);         sp = (spinner) findviewbyid(r.id.spinner);         spinner2 = (spinner) findviewbyid(r.id.spinner2);         t2=(textview) findviewbyid(r.id.textview2);         //creating adapter         arrayadapter<string> adapter_state = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, notes);         arrayadapter<string> adapter_state2 = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, mode);          //setting drop down list type         adapter_state.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);         adapter_state2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);          //setting adapter spinner         sp.setadapter(adapter_state);         spinner2.setadapter(adapter_state2);          //setting listener spinner         sp.setonitemselectedlistener(this);         spinner2.setonitemselectedlistener(this);     }      @override     public void onitemselected(adapterview<?> parent, view view, int position, long id) {         imgview = (imageview) findviewbyid(r.id.imageview);         mysound = mediaplayer.create(this, r.raw.am);         mysound2 = mediaplayer.create(this, r.raw.em);         mysound3 = mediaplayer.create(this, r.raw.amajor);         mysound4 = mediaplayer.create(this, r.raw.cmajor);         mysound5 = mediaplayer.create(this, r.raw.gmajor);         mysound6 = mediaplayer.create(this, r.raw.dminor);         mysound7 = mediaplayer.create(this, r.raw.bm);          if (sp.getselecteditemposition() == 0 && spinner2.getselecteditemposition() == 0) {             mysound.start();             imgview.setimageresource(images[0]);         }         if (sp.getselecteditemposition() == 0 && spinner2.getselecteditemposition() == 3) {             mysound3.start();             imgview.setimageresource(images[2]);         }         if (sp.getselecteditemposition() == 1 && spinner2.getselecteditemposition() == 0) {             mysound7.start();             imgview.setimageresource(images[6]);         }         if (sp.getselecteditemposition() == 2 && spinner2.getselecteditemposition() == 3) {             mysound4.start();             imgview.setimageresource(images[3]);         }         if (sp.getselecteditemposition() == 4 && spinner2.getselecteditemposition() == 0) {             mysound6.start();             imgview.setimageresource(images[5]);         }         if (sp.getselecteditemposition() == 5 && spinner2.getselecteditemposition() == 0) {             mysound2.start();             imgview.setimageresource(images[1]);         }         if (sp.getselecteditemposition() == 8 && spinner2.getselecteditemposition() == 3) {             mysound5.start();             imgview.setimageresource(images[4]);         }     }     public void onnothingselected(adapterview<?> parent) {         // todo auto-generated method stub      } } 

mysound = mediaplayer.create(this, r.raw.am); mysound2 = mediaplayer.create(this, r.raw.em); mysound3 = mediaplayer.create(this, r.raw.amajor); mysound4 = mediaplayer.create(this, r.raw.cmajor); mysound5 = mediaplayer.create(this, r.raw.gmajor); mysound6 = mediaplayer.create(this, r.raw.dminor); mysound7 = mediaplayer.create(this, r.raw.bm); 

don't this. create 1 mediaplayer. mediaplayer big bulky object, creating 7 of them extremely painful , slow. shouldn't creating new 1 on every click, should created in oncreate , new data source set instead.


Comments