android之datepicker控件的用法

android之datepicker控件的用法,第1张

概述如下所示:<?xmlversion=\"1.0\"encoding=\"utf-8\"?><LinearLayoutxmlns:android=\"http://schemas.android.com/apk/res/android\"

如下所示:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:orIEntation="vertical"  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  ><TextVIEw   androID:ID="@+ID/textVIEwDatedisplay"   androID:layout_wIDth="wrap_content"   androID:layout_height="wrap_content"   /><button   androID:ID="@+ID/btnPickDate"  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  androID:text="Change the date"  /></linearLayout>
package com.example.mars_2200_datepicker;import java.util.Calendar;import androID.support.v7.app.ActionBaractivity;import androID.support.v7.app.Actionbar;import androID.support.v4.app.Fragment;import androID.app.DatePickerDialog;import androID.app.Dialog;import androID.os.Bundle;import androID.vIEw.LayoutInflater;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.button;import androID.Widget.DatePicker;import androID.Widget.TextVIEw;import androID.os.Build;public class MainActivity extends ActionBaractivity {  private TextVIEw textVIEwDatedisplay;  private button btnPickDate;  private int mYear;  private int mMonth;  private int mDay;  static final int DATE_DIALOG_ID = 0;  @OverrIDe  protected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    textVIEwDatedisplay = (TextVIEw) findVIEwByID(R.ID.textVIEwDatedisplay);    btnPickDate = (button) findVIEwByID(R.ID.btnPickDate);    btnPickDate.setonClickListener(new VIEw.OnClickListener() {      public voID onClick(VIEw v) {        showDialog(DATE_DIALOG_ID);      }    });    final Calendar c = Calendar.getInstance();    mYear = c.get(Calendar.YEAR);    mMonth = c.get(Calendar.MONTH);    mDay = c.get(Calendar.DAY_OF_MONTH);    updatedisplay();  }  @OverrIDe  public boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.main,menu);    return true;  }  @OverrIDe  public boolean onoptionsItemSelected(MenuItem item) {    // Handle action bar item clicks here. The action bar will    // automatically handle clicks on the Home/Up button,so long    // as you specify a parent activity in AndroIDManifest.xml.    int ID = item.getItemID();    if (ID == R.ID.action_settings) {      return true;    }    return super.onoptionsItemSelected(item);  }  /**   * A placeholder fragment containing a simple vIEw.   */  public static class PlaceholderFragment extends Fragment {    public PlaceholderFragment() {    }    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) {      VIEw rootVIEw = inflater.inflate(R.layout.fragment_main,container,false);      return rootVIEw;    }  }  private voID updatedisplay() {    textVIEwDatedisplay.setText(new StringBuilder().append(mYear).append("-")        .append(mMonth + 1).append("-").append(mDay).append(" "));  }  private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {    public voID onDateSet(DatePicker vIEw,int year,int monthOfYear,int dayOfMonth) {      mYear = year;      mMonth = monthOfYear;      mDay = dayOfMonth;      updatedisplay();    }  };  protected Dialog onCreateDialog(int ID) {    switch (ID) {    case DATE_DIALOG_ID:      return new DatePickerDialog(this,mDateSetListener,mYear,mMonth,mDay);    }    return null;  }}

以上就是小编为大家带来的androID之datepicker控件用法的全部内容了,希望对大家有所帮助,多多支持编程小技巧~

总结

以上是内存溢出为你收集整理的android之datepicker控件的用法全部内容,希望文章能够帮你解决android之datepicker控件的用法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1148048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存