Home>

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.ljq.dialog"
 android:versioncode="1"
 android:versionname="1.0">
 <application android:icon="@ drawable/icon" android:label="@ string/app_name">
 <activity android:name=". Alertdialog"
   android:label="@ string/app_name">
  <intent-filter>
  <action android:name="android.intent.action.main" />
  <category android:name="android.intent.category.launcher" />
  </intent-filter>
 </activity>
 </application>
 <uses-sdk android:minsdkversion="7" />
 <uses-permission android:name="android.permission.write_calendar" />
</manifest>

main.xml layout file:

<?xml version="1.0" encoding="utf-8"?>
<linearlayout android:id="@ + id/linearlayout01"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 android:orientation="vertical"
 xmlns:android="http://schemas.android.com/apk/res/android">
 <edittext android:id="@ + id/et"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:editable="false"
 android:cursorvisible="false" />
 <button android:text="Date Dialog"
 android:id="@ + id/datebtn"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />
 <button android:text="time dialog"
 android:id="@ + id/timebtn"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />
 <digitalclock
 android:text="@ + id/digitalclock"
 android:textsize="20dip"
 android:gravity="center"
 android:id="@ + id/digitalclock01"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />
 <analogclock
 android:id="@ + id/analogclock"
 android:gravity="center"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />
</linearlayout>

alertactivity class:

package com.ljq.dialog;
import java.util.calendar;
import android.app.activity;
import android.app.datepickerdialog;
import android.app.dialog;
import android.app.timepickerdialog;
import android.os.bundle;
import android.view.view;
import android.widget.button;
import android.widget.datepicker;
import android.widget.edittext;
import android.widget.timepicker;
public class alertdialog extends activity {
 private button datebtn=null;
 private button timebtn=null;
 private edittext et=null;
 private final static int date_dialog=0;
 private final static int time_dialog=1;
 private calendar c=null;
 @override
 public void oncreate (bundle savedinstancestate) {
 super.oncreate (savedinstancestate);
 setcontentview (r.layout.main);
 et=(edittext) findviewbyid (r.id.et);
 datebtn=(button) findviewbyid (r.id.datebtn);
 timebtn=(button) findviewbyid (r.id.timebtn);
 datebtn.setonclicklistener (new view.onclicklistener () {
  public void onclick (view v) {
  showdialog (date_dialog);
  }
 });
 timebtn.setonclicklistener (new view.onclicklistener () {
  public void onclick (view v) {
  showdialog (time_dialog);
  }
 });
 }
 /**
 * Create date and time selection dialog
 * /
 @override
 protected dialog oncreatedialog (int id) {
 dialog dialog=null;
 switch (id) {
 case date_dialog:
  c=calendar.getinstance ();
  dialog=new datepickerdialog (
  this,  new datepickerdialog.ondatesetlistener () {
   public void ondateset (datepicker dp, int year, int month, int dayofmonth) {
   et.settext ("You have selected:" + year + "year" + (month + 1) + "month" + dayofmonth + "day");
   }
  },  c.get (calendar.year), //pass in the year
  c.get (calendar.month), //pass in the month
  c.get (calendar.day_of_month) //Incoming days
  );
  break;
 case time_dialog:
  c=calendar.getinstance ();
  dialog=new timepickerdialog (
  this,  new timepickerdialog.ontimesetlistener () {
   public void ontimeset (timepicker view, int hourofday, int minute) {
   et.settext ("You have selected:" + hourofday + "" + minute + "");
   }
  },  c.get (calendar.hour_of_day),  c.get (calendar.minute),  false
  );
  break;
 }
 return dialog;
 }
}

operation result:

  • Previous How js determines if a visit is from a search engine (spider-man) or a direct visit
  • Next PowerShell tips for sharing