User Interface's Picker

Source: Internet
Author: User

I. Timepicker

1. Create timepickerfragment

Package Com.panjn.userinterface;import Android.app.dialog;import Android.app.timepickerdialog;import Android.os.bundle;import Android.support.annotation.nonnull;import Android.support.v4.app.dialogfragment;import Android.widget.timepicker;import android.widget.toast;import Java.text.dateformat;import java.util.Calendar;/** * Created by panjianning on 2016/7/6. */public class Timepickerfragment extends Dialogfragment implements Timepickerdialog.ontimesetlistener {@NonNull @O Verride public Dialog Oncreatedialog (Bundle savedinstancestate) {//Use the current time as the default values        For the picker final Calendar calendar = Calendar.getinstance ();        int hour = Calendar.get (Calendar.hour_of_day);        int min = Calendar.get (calendar.minute);         /** * Params * contextthe Parent context * Listenerthe listener to call when the time is set * Hourofdaythe Initial Hour * minute the initial minute * is24HourViewwhether This is a hour view or AM/PM */return new Timepickerdialog (Getactivity (), this, hour,    Min, True);  } @Override public void Ontimeset (timepicker view, int hourofday, int. minute) {//do something with the time Chosen by the user}}

2. Display timepickerfragment

public void Showtimepickerdialog (View v) {    dialogfragment newfragment = new Timepickerfragment ();    Newfragment.show (Getsupportfragmentmanager (), "Timepicker");}

Two. DatePicker

1. Create datepickerfragement

public static class Datepickerfragment extends Dialogfragment                            implements Datepickerdialog.ondatesetlistener {    @Override public    Dialog oncreatedialog (Bundle savedinstancestate) {//Use the current date as the        default Da Te in the picker        final Calendar c = calendar.getinstance ();        int year = C.get (calendar.year);        int month = C.get (calendar.month);        int day = C.get (calendar.day_of_month);        Create a new instance of Datepickerdialog and return it        return new Datepickerdialog (Getactivity (), this, year, Mont h, day);    }    public void Ondateset (DatePicker view, int year, int month, Int. day) {        //do something with the date chosen by the US Er    }}

 2. Display datepickerfragment

public void Showdatepickerdialog (View v) {    dialogfragment newfragment = new Datepickerfragment ();    Newfragment.show (Getsupportfragmentmanager (), "DatePicker");}

  

User Interface's Picker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.