Home>

First, the time selector1.1. Layout

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 tools:context="com.rj141.sb.kongjian.dateactivity">
 <linearlayout
 android:orientation="horizontal"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
 <textview
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textsize="20dp"
  android:text="What time to eat:"
  />
 <textview
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textsize="20dp"
  android:id="@ + id/tv" />
 </linearlayout>
 <button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="time"
 android:id="@ + id/btndate" />
</linearlayout>

1.2.java file

public class dateactivity extends actionbaractivity {
 private button btn;
 private textview tv;
 @override
 protected void oncreate (bundle savedinstancestate) {
 super.oncreate (savedinstancestate);
 setcontentview (r.layout.activity_date);
 btn=(button) this.findviewbyid (r.id.btndate);
 tv=(textview) this.findviewbyid (r.id.tv);
 btn.setonclicklistener (new view.onclicklistener () {
  @override
  public void onclick (view v) {
  new timepickerdialog (dateactivity.this, new timepickerdialog.ontimesetlistener () {
   @override
   public void ontimeset (timepicker view, int hourofday, int minute) {
   tv.settext (string.format ("%d:%d", hourofday, minute));
   }
  // 0,0 refers to time,true indicates whether it is 24 hours, true is a 24-hour clock
  }, 0,0, true) .show ();
  }
 });
 }
}

Effect picture:

Date picker2.1.activity.xml

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.rj141.sb.kongjian.dateactivity">
<textview
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textsize="20dp"
android:id="@ + id/tv" />
<button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calendar"
android:id="@ + id/btndate" />
</linearlayout>

2.2.dateactivity.class

public class dateactivity extends actionbaractivity {
private button btn;
private textview tv;
@override
protected void oncreate (bundle savedinstancestate) {
super.oncreate (savedinstancestate);
setcontentview (r.layout.activity_date);
btn=(button) this.findviewbyid (r.id.btndate);
tv=(textview) this.findviewbyid (r.id.tv);
btn.setonclicklistener (new view.onclicklistener () {
@override
public void onclick (view v) {
new datepickerdialog (dateactivity.this, new datepickerdialog.ondatesetlistener () {
@override
public void ondateset (datepicker view, int year, int monthofyear, int dayofmonth) {
tv.settext ("Your birth date is:" + string.format ("%d-%d-%d", year, monthofyear + 1, dayofmonth));
}
}, 2000,1,2) .show ();
}
});
}
}
datepickerdialog calendar selector dialog,Listen for ondatesetlistener () {..}

Effect picture:

  • Previous Visual Studio 2013 update introduction
  • Next Ichartjs implementation code for drawing dashed lines and averaged dotted lines