我在Android中构建了一个简单的音乐播放器.每首歌曲的视图都包含一个SeekBar,实现方式如下:
public class Song extends Activity implements OnClickListener,Runnable {
private SeekBar progress;
private MediaPlayer mp;
// ...
private ServiceConnection onService = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder rawBinder) {
appService = ((MPService.LocalBinder)rawBinder).getService(); // service that handles the MediaPlayer
progress.setVisibility(SeekBar.VISIBLE);
progress.setProgress(0);
mp = appService.getMP();
appService.playSong(title);
progress.setMax(mp.getDuration());
new Thread(Song.this).start();
}
public void onServiceDisconnected(ComponentName classname) {
appService = null;
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.song);
// ...
progress = (SeekBar) findViewById(R.id.progress);
// ...
}
public void run() { …Run Code Online (Sandbox Code Playgroud) 我是Android的新手,并通过以下
示例学习如何在Android中创建片段:片段导航抽屉
在菜单项和添加导航标题之间导航之间的代码包含一种方法getActivity().
由于作者没有提到粘贴此代码的位置,我粘贴在我的MainActivity.java文件中
菜单项之间的导航和添加导航标题之间的代码是否由我粘贴在正确的位置?
在方法中selectDrawerItem(MenuItem menuItem)有一个评论// Create a new fragment and specify the planet to show based on position
作者希望我在这里添加一些东西.