..

jeudi 19 mars 2015

[Q] Why is this bit of code not working? topic


In the activity.xml:

<ToggleButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/SoundToggle"
android:textOn="Music is Off"
android:textOff="Music is On"
android:onClick="ToggleSound"/>

in the java.xml:

public void ToggleSound(View view) {
boolean toggleMusic = ((ToggleButton) view).isChecked();
if (toggleMusic)
{
titleSound.stop();
}
else
{
titleSound.start();

at this, the titleSound (Which is a song in the background) Will stop playing when I toggle the button to ON, however it will never start playing again, no matter how long I wait (up to 10 minutes, at least) and how much I spam the button...

xda-developers