Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see where you are replacing the content of </p> <pre><code>R.raw.sound1 </code></pre> <p>which you are passing as an argument, thus, as I can observe in your code, you are saving the same sound every time you call the saving methods.</p> <p>EDIT:</p> <ol> <li><p>Create int variable which will hold the info about last selected sound:</p> <p>int selectedSoundId;</p></li> <li><p>In onClickListener set the selectedSoundId to sound id connected with current button:</p> <p>if(v.getId() == buttonIds[i]) { selectedSoundId = soundIds[i]; //rest of the code }</p></li> <li><p>Pass the selectedSoundId to savering and savenot methods:</p> <p>savering(selectedSoundId); savenot(selectedSoundId);</p></li> </ol> <p>Hope this helps.</p> <p>EDIT 2: I'm pasting your code with my corrections.</p> <p>Ad.2. This is the part when you need to save the info about current sound id.</p> <pre><code>final int[] buttonIds = { R.raw.sound1 "etc all buttons here"}; final int[] soundIds = {R.raw.sound1 "etc all sounds here"}; View.OnClickListener listener = new View.OnClickListener() { public void onClick(View v) { //find the index that matches the button's ID, and then reset //the MediaPlayer instance, set the data source to the corresponding //sound effect, prepare it, and start it playing. for(int i = 0; i &lt; buttonIds.length; i++) { if(v.getId() == buttonIds[i]) { selectedSoundId = soundIds[i]; AssetFileDescriptor afd = res.openRawResourceFd(soundIds[i]); player.reset(); try { player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { player.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } player.start(); break; } } } }; </code></pre> <p>Ad.3. This is the part of calling the savering and savenot methods.</p> <pre><code>if (savering(selectedSoundId)){ // Code if successful Toast.makeText(this, "Saved as Ringtone", Toast.LENGTH_SHORT).show(); } else { // Code if unsuccessful Toast.makeText(this, "Failed - Check your SDCard", Toast.LENGTH_SHORT).show(); } } public void function2(int id){ if (savenot(selectedSoundId)){ // Code if successful Toast.makeText(this, "Saved as Notification", Toast.LENGTH_SHORT).show(); } else { // Code if unsuccessful Toast.makeText(this, "Failed - Check your SDCard", Toast.LENGTH_SHORT).show(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload