Home>

how to use

import java.text.dateformat;
import java.text.parseexception;
import java.text.simpledateformat;
import java.util.calendar;
import android.app.activity;
import android.app.alertdialog;
import android.content.dialoginterface;
import android.os.bundle;
import android.view.layoutinflater;
import android.view.view;
import android.view.view.onclicklistener;
import android.widget.button;
import android.widget.edittext;
public class mainactivity extends activity {
 wheelmain wheelmain;
 edittext txttime;
 dateformat dateformat=new simpledateformat ("yyyy-mm-dd");
 @override
 public void oncreate (bundle savedinstancestate) {
  super.oncreate (savedinstancestate);
  setcontentview (r.layout.main);
  txttime=(edittext) findviewbyid (r.id.txttime);
  calendar calendar=calendar.getinstance ();
  txttime.settext (calendar.get (calendar.year) + "-"
    + (calendar.get (calendar.month) + 1) + "-"
    + calendar.get (calendar.day_of_month) + "");
  button btnselecttime=(button) findviewbyid (r.id.button1);
  btnselecttime.setonclicklistener (new onclicklistener () {
   @override
   public void onclick (view arg0) {
    layoutinflater inflater=layoutinflater
      .from (mainactivity.this);
    final view timepickerview=inflater.inflate (
      r.layout.timepicker, null);
    screeninfo screeninfo=new screeninfo (mainactivity.this);
    wheelmain=new wheelmain (timepickerview, true);
    wheelmain.screenheight=screeninfo.getheight ();
    string time=txttime.gettext (). tostring ();
    calendar calendar=calendar.getinstance ();
    if (judgedate.isdate (time, "yyyy-mm-dd")) {
     try {
      calendar.settime (dateformat.parse (time));
     } catch (parseexception e) {
      //todo auto-generated catch block
      e.printstacktrace ();
     }
    }
    int year=calendar.get (calendar.year);
    int month=calendar.get (calendar.month);
    int day=calendar.get (calendar.day_of_month);
    int h=calendar.gettime (). gethours ();
    int m=calendar.gettime (). getminutes ();
    wheelmain.initdatetimepicker (year, month, day, h, m);
    new alertdialog.builder (mainactivity.this)
      .settitle ("Select Time")
      .setview (timepickerview)
      .setpositivebutton ("OK",        new dialoginterface.onclicklistener () {
         @override
         public void onclick (dialoginterface dialog,           int which) {
          txttime.settext (wheelmain.gettime ());
         }
        })
      .setnegativebutton ("Cancel",        new dialoginterface.onclicklistener () {
         @override
         public void onclick (dialoginterface dialog,           int which) {
         }
        }). show ();
   }
  });
 }
}
  • Previous Java Swing multi-threaded loading images (guaranteed order)
  • Next Android click WebView to achieve picture zoom and slide browsing effect