android常用控件总结(7)
发布时间:2021-06-06
发布时间:2021-06-06
android 常用控件总结
//从main.xml布局中获得Button对象
Button button_start = (Button)findViewById(R.id.start);
Button button_stop = (Button)findViewById(R.id.stop);
//设置按钮(Button)监听
button_start.setOnClickListener(start);
button_stop.setOnClickListener(stop);
}
//开始按钮
private OnClickListener start = new OnClickListener(){
public void onClick(View v){
//开启Service
startService(new Intent("com.yarin.Android.MUSIC"));
}
};
//停止按钮
private OnClickListener stop = new OnClickListener(){
public void onClick(View v){
//停止Service
stopService(new Intent("com.yarin.Android.MUSIC"));
}
};
}
public class MusicService extends Service{
//MediaPlayer对象
private MediaPlayer player;
public IBinder onBind(Intent arg0){
return null;
}
public void onStart(Intent intent, int startId){
super.onStart(intent, startId);
上一篇:铺邑小学读书节启动仪式主持词
下一篇:小学体育障碍跑教案