欢迎来到天天文库
浏览记录
ID:37708203
大小:77.00 KB
页数:21页
时间:2019-05-29
《Android开发闹钟(详细开发步骤)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、MainActivity中的代码:packagecom.cn.daming;importjava.util.Calendar;importandroid.app.Activity;importandroid.app.AlarmManager;importandroid.app.AlertDialog;importandroid.app.PendingIntent;importandroid.app.TimePickerDialog;importandroid.content.DialogInterface;importandroid.content.Intent;importan
2、droid.content.SharedPreferences;importandroid.os.Bundle;importandroid.view.KeyEvent;importandroid.view.LayoutInflater;importandroid.view.MotionEvent;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.TextView;importandroid.widget.TimePicker;im
3、portandroid.widget.Toast;publicclassMainActivityextendsActivity{TextViewsetTime1;TextViewsetTime2;TextViewsetTime3;ButtonmButton1;ButtonmButton2;ButtonmButton3;ButtonmButton4;ButtonmButton5;ButtonmButton6;Stringtime1String=null;Stringtime2String=null;Stringtime3String=null;StringdefalutString="
4、目前无设置";AlertDialogbuilder=null;Calendarc=Calendar.getInstance();@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);//取得活动的Preferences对象SharedPreferencessettings=getPreferences(Activity.MODE_PRIVATE);time1String=settings.getStri
5、ng("TIME1",defalutString);time2String=settings.getString("TIME2",defalutString);time3String=settings.getString("TIME3",defalutString);InitButton1();InitButton2();InitButton3();InitButton4();InitButton5();InitButton6();setTime1.setText(time1String);setTime3.setText(time2String);setTime2.setText(
6、time3String);}publicvoidInitButton1(){setTime1=(TextView)findViewById(R.id.setTime1);mButton1=(Button)findViewById(R.id.mButton1);mButton1.setOnClickListener(newView.OnClickListener(){publicvoidonClick(Viewv){c.setTimeInMillis(System.currentTimeMillis());intmHour=c.get(Calendar.HOUR_OF_DAY);int
7、mMinute=c.get(Calendar.MINUTE);newTimePickerDialog(MainActivity.this,newTimePickerDialog.OnTimeSetListener(){publicvoidonTimeSet(TimePickerview,inthourOfDay,intminute){c.setTimeInMillis(System.currentTimeMillis());c.set(Calendar.H
此文档下载收益归作者所有