android設置時間widget,【Android】時間與日期Widget(DatePicker 與 TimePicker)

public class Activity01 extends Activity

{

TextViewm_TextView;

//聲明dataPicker

DatePickerm_DatePicker;

//聲明TimePicker

TimePickerm_TimePicker;

Button m_dpButton;

Button m_tpButton;

//java中的Calendar類

Calendar c;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

c=Calendar.getInstance();

m_TextView= (TextView) findViewById(R.id.TextView01);

m_dpButton = (Button)findViewById(R.id.button1);

m_tpButton = (Button)findViewById(R.id.button2);

//獲取DataPicker對象

m_DatePicker = (DatePicker) findViewById(R.id.DatePicker01);

//初始化當前時間并設置監聽

m_DatePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {

@Override

public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth)

{

//當日期更改在這里設置

c.set(year, monthOfYear, dayOfMonth);

}

});

//

m_TimePicker = (TimePicker) findViewById(R.id.TimePicker01);

//

m_TimePicker.setIs24HourView(true);

//

m_TimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

@Override

public void onTimeChanged(TimePicker view, int hourOfDay, int minute)

{

//當時間更改在這里設置

c.set(year, month, day, hourOfDay, minute, second);

}

});

m_dpButton.setOnClickListener(new Button.OnClickListener(){

public void onClick(View v)

{

new DatePickerDialog(Activity01.this,

new DatePickerDialog.OnDateSetListener()

{

public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)

{

//設置日歷

}

},c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();

}

});

m_tpButton.setOnClickListener(new Button.OnClickListener() {

public void onClick(View v)

{

new TimePickerDialog(Activity01.this,

new TimePickerDialog.OnTimeSetListener()

{

public void onTimeSet(TimePicker view, int hourOfDay,int minute)

{

//設置時間

}

},c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();

}

});

}

}

對應的layout文件<?xml version="1.0" encoding="utf-8"?>

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/TextView1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

android:id="@+id/Button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

>

android:id="@+id/Button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278878.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278878.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278878.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

初學者java學習計劃_初學者:計劃在Windows 7 Media Center中錄制直播電視的時間

初學者java學習計劃If you’re a new user to Windows 7 Media Center you know it can act as a DVR and pause or record Live TV. You can set up a schedule for it to record your favorite TV programs as well. 如果您是Windows 7 Media Center的新用戶&#xff0c;則知…

雙數據源配置

從此抄錄&#xff1a;https://blog.csdn.net/ll535299/article/details/78203634 1、先配置兩個數據源&#xff0c;附上主要代碼&#xff0c;給自己回憶&#xff0c;詳解見開頭鏈接 <!-- 配置數據源 --> <bean id"szDS" class"com.alibaba.druid.pool.…

如何在Office 2007中查看關于對話框和版本信息

One of our favorite readers wrote in today asking how to tell if his Word 2007 installation was running Service Pack 1, since he couldn’t find the About dialog, which got me thinking… I bet most people don’t know where it is! 我們最喜歡的一位讀者今天寫信…

windows全局熱鍵_在Windows中創建快捷方式或熱鍵以清除剪貼板

windows全局熱鍵Have you ever copied something to the clipboard that you don’t want to leave there in case somebody else is going to use your computer? Sure, you can copy something else to the clipboard real quick, but can’t you just make a shortcut or h…

android+notepad教程,Android Sample學習——NotePad

android.view.Menu專場Interface for managing the items in a menu.By default, every Activity supports an options menu of actions or options. You can add items to this menu and handle clicks on your additions. The easiest way of adding menu items is inflating…

Windows應用程序開發

Windows窗體應用程序開發&#xff1a;WinForm、桌面應用程序&#xff0c;有可執行文件(.exe)即安裝包。是一種C/S&#xff08;客戶機/服務器&#xff09;架構應用程序 1.Windows窗體應用程序&#xff0c;用可視化的窗體和控件生成豐富界面的&#xff0c;可交互操作的應用程序。…

獲取outlook 會議_如何僅在Microsoft Outlook中僅獲取您關注的電子郵件的通知

獲取outlook 會議Some emails are more important than others. Rather than getting alerts every time an email arrives, configure Microsoft Outlook to only alert you when the important stuff hits your inbox, rather than any old email that can wait until you ch…

jq html 多一個引號,為什么jQuery模板會為某些字符串添加雙引號

背景我正在使用jQuery模板,ASP.Net MVC Razor視圖和Twitter.問題使用帶有一些字符串的jQuery模板會自動導致這些字符串被包含在“細節我創建了一個如下所示的jQuery模板&#xff1a;before ${text.parseUserName().parseHashTag()} after${created_at}${prettyDate(created_at)…

從Windows計算機上完全刪除iTunes和其他Apple軟件

If you are giving up on iTunes for another music player, uninstalling it completely can be a hassle. Here we show you how to completely remove all traces of it including QuickTime, iTunes Helper, Bonjour…all of it. 如果您在iTunes上放棄了其他音樂播放器&…

html仿微信滑動刪除,使用Vue實現移動端左滑刪除效果附源碼

左滑刪除在移動端是很常見的一種操作&#xff0c;常見于刪除購物車中的商品&#xff0c;刪除收藏夾中文章等等場景。我們只需要手指按住要刪除的對象&#xff0c;然后輕輕向左滑動&#xff0c;便會出現刪除按鈕&#xff0c;然后點擊刪除按鈕即可刪除對象。點擊下載源碼今天我給…

推薦書本_

1. c#_設計模式 《設計模式&#xff1a;可復用面向對象軟件的基礎》GoF 《面向對象分析與設計》Grady Booch 《敏捷軟件開發&#xff1a;原則、模式與實踐》 Robert C.Martin 《重構&#xff1a;改善既有代碼的設計》 Martin Fowler 《Refactoring to Patterns》Jshua Kerievsk…

h5 領取優惠券 下載_下載7天免費試用版或購買VideoProc,可享受60%優惠券[贊助的帖子]...

h5 領取優惠券 下載You may have seen piles of video editing tools, but here we’ll show you a different one – VideoProc, developed by Digiarty Software, Inc. It is not a “standard” video editing program. Some consider VideoProc a complete toolbox also fo…

html走馬觀花效果,走馬觀花臺灣行 用EF-S 10-18來記錄風景

我在6月初入手無忌第一支10-18&#xff0c;初步測試后對其表現比較滿意&#xff0c;具體可看http://forum.xitek.com/thread-1314865-1-1-1.html。7月初到8月中旬我都處于旅行狀態中&#xff0c;佳能系統帶了三支鏡&#xff0c;包括EFS10-18&#xff0c;EFS55-250和EF24IS&…

一大波學習內容!

Dubbo-大波-服務化框架 dubbo_百度搜索Dubbo與Zookeeper、SpringMVC整合和使用&#xff08;負載均衡、容錯&#xff09; - 好庫文摘User Guide-zh - Dubbo - Alibaba Open SesameUser Guide-zh - Dubbo - Alibaba Open Sesame簡單之美 | Dubbo架構設計詳解DUBBOHprose RPC框架 …

文件下載至storage_如何防止Storage Sense在Windows 10上刪除下載的文件

文件下載至storageStorage Sense is the Disk Cleanup replacement for the modern world. It frees up space on your computer by deleting things like recycle bin contents, temporary internet files, and app temporary files. This also includes the Downloads folder…

html標簽屬性和標簽事件,HTML參考手冊( 標簽、屬性和事件)

HTML標簽標簽 描述 DTD定義注釋。 STF定義文檔類型。 STF定義錨。 STF定義縮寫。 STF定義只取首字母的縮寫。 STF定義文檔作者或擁有者的聯系信息。 STF 不贊成使用。定義嵌入的 applet。 TF 定義圖像映射內部的區域。 STF 定義粗體字。 STF 定義頁面中所有鏈接的默認地址或默認…

Feign從配置文件中讀取url

Feign的url和name都是可配置的&#xff0c;就是從配置文件中讀取的屬性值&#xff0c;然后用占位符引用就可以了&#xff1a; ${rpc.url} FeignClient(name "me",url "${rpc.url}", // 這里是可以配置的, 就不用再硬編碼了fallbackFactory MyHystrixFa…

百度地圖精確定位html,HTML5地理定位,百度地圖API,知識點熟悉

深入seajs源碼系列三入口方法 每個程序都有個入口方法,類似于c的main函數,seajs也不例外.系列一的demo在首頁使用了seajs.use(),這便是入口方法.入口方法可以接受2個參數,第一個參數為模塊名稱,第二個 ...javscript創建Emitter本文簡單敘述下javascript是如何建立一個Emitter構…

如何搭建html運行環境,搭建真實的運行環境2019.4.22

1、搭建真實運行環境步驟①先下載phpstudy軟件②按照安裝步驟進行phpstudy安裝&#xff0c;安裝后啟動服務&#xff0c;點擊《其它選項菜單》里面的《My HomePage》選項&#xff0c;正常顯示&#xff0c;說明安裝成功2、創建本地訪問目錄和域名①打開phpstudy&#xff0c;點擊《…

supervisord的安裝使用

由于生產環境使用的的tomcat&#xff0c;項目比較重要&#xff0c;所以要做進程守護&#xff0c;本來打算自己寫腳本&#xff0c;但是效果不理想&#xff0c;想了下還是用supervisord了 由于很久不用&#xff0c;所以寫下來部署步驟 第一&#xff1a;安裝&#xff0c;安裝的方法…