OnTimeChangedListener(日期和时间的事件处理)
DatePicker

/*取得DatePicker对象,以init()设置初始值与OnDateChangedListener()*/ DatePicker dp= (DatePicker)findViewById(R.id.DatePicker01); dp.init (year, month, day, new OnDateChangedListener () { public void onDateChanged(DatePicker view,int Year,int monthOfYear,int dayOfMonth) {} });
TimePicker

/*取得TimePicker对象,并设置为24小时制*/ TimePicker tp= (TimePicker)findViewById(R.id.TimePicker01); tp.setIs24HourView (true); tp.setOnTimeChangedListener (new OnTimeChangedListener () { public void onTimeChanged(TimePicker view, int hourOfDay, int Minute) {} });
OnLongClickListener(长按事件)
修改AndroidMainfest.xml文件,增加授权操作:
<uses - permission android: name="android. permission. SET_WALLPAPER"/>

//取得TextView TextView info= (TextView)super. findViewById (R.id. TextView); //取得ImageView控件 ImageView image= (ImageView)super. findViewById (R.id. ImageView); image.setOnLongClickListener(new OnLongClickListener(){ //长按监听 public boolean onLongClick(View v) { //长按事件 try { 类名.this.clearWallpaper(); //清除桌面 //设置新的桌面背景 类名.this.setWallpaper( 类名.this. image.getResources(). openRawResource(R.drawable.图片名)); //修改显示文字 类名.this.info.setText("手机桌面背景已修改"); } catch (IOException e) { 类名.this.info.setText("手机桌面背景设置失败"); } return true; } );