我正试图将这些歌曲设置为Radio Buttons,一次播放一首,而不是互相播放,一旦完成,一旦点击就不再播放。
我有一个单独的Radio Group,每个音轨有18个单选按钮,我不知道在switch语句中每个case的内部放置什么Java代码,以便在单击另一个时再次播放歌曲并重新播放一旦重新点击。任何帮助将不胜感激,提前感谢。
package com.example.adiodopeheadz;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.os.Build;
public class MainActivity extends Activity implements OnCheckedChangeListener,
OnClickListener {
MediaPlayer track1, track2, track3, track4, track5, track6, track7, track8,
track9, track10, track11, track12, track13, track14, track15, track16, track17,
track18;
Button Team;
Button Shows;
Button Contact;
RadioGroup tracks;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
Team = (Button) findViewById(R.id.button1);
Contact = (Button) findViewById(R.id.button3);
track1 = MediaPlayer.create(MainActivity.this, R.raw.track1);
track2 = MediaPlayer.create(MainActivity.this, R.raw.track2);
track3 = MediaPlayer.create(MainActivity.this, R.raw.track3);
track4 = MediaPlayer.create(MainActivity.this, R.raw.track4);
track5 = MediaPlayer.create(MainActivity.this, R.raw.track5);
track6 = MediaPlayer.create(MainActivity.this, R.raw.track6);
track7 = MediaPlayer.create(MainActivity.this, R.raw.track7);
track8 = MediaPlayer.create(MainActivity.this, R.raw.track8);
track9 = MediaPlayer.create(MainActivity.this, R.raw.track9);
track10 = MediaPlayer.create(MainActivity.this, R.raw.track10);
track11 = MediaPlayer.create(MainActivity.this, R.raw.track11);
track12 = MediaPlayer.create(MainActivity.this, R.raw.track12);
track13 = MediaPlayer.create(MainActivity.this, R.raw.track13);
track14 = MediaPlayer.create(MainActivity.this, R.raw.track14);
track15 = MediaPlayer.create(MainActivity.this, R.raw.track15);
track16 = MediaPlayer.create(MainActivity.this, R.raw.track16);
track17 = MediaPlayer.create(MainActivity.this, R.raw.track17);
track18 = MediaPlayer.create(MainActivity.this, R.raw.track18);
tracks = (RadioGroup) findViewById(R.id.rg1);
tracks.setOnCheckedChangeListener(this);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
switch(arg1){
case R.id.track1:
break;
case R.id.track2:
break;
case R.id.track3:
break;
case R.id.track4:
break;
case R.id.track5:
break;
case R.id.track6:
break;
case R.id.track7:
break;
case R.id.track8:
break;
case R.id.track9:
break;
case R.id.track10:
break;
case R.id.track11:
break;
case R.id.track12:
break;
case R.id.track13:
break;
case R.id.track14:
break;
case R.id.track15:
break;
case R.id.track16:
break;
case R.id.track17:
break;
case R.id.track18:
break;
}
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}