Android Studio時(shí)間選擇器的創(chuàng)建方法
本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下
效果顯示:
1、創(chuàng)建xml頁面(我的項(xiàng)目扣下來的,有的地方會報(bào)錯(cuò)要改)
<TextView android:id="@+id/consultation_tv_birthdate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/consultation_tv_sex" android:layout_alignStart="@+id/consultation_tv_sex" android:layout_alignTop="@+id/consultation_et_birthdate" android:layout_marginTop="9dp" android:text="出生日期:" android:textColor="@color/black" android:textSize="18sp" android:textStyle="bold" /> <EditText android:id="@+id/consultation_et_birthdate" android:layout_width="260dp" android:layout_height="40dp" android:layout_alignLeft="@+id/consultation_et_sex" android:layout_alignStart="@+id/consultation_et_sex" android:layout_below="@+id/consultation_et_sex" android:layout_marginTop="22dp" android:background="@drawable/input_bg" android:focusable="false" android:ems="10" android:inputType="textPersonName" android:paddingLeft="15dp" android:paddingRight="15dp" /> <ImageView android:id="@+id/consultation_iv_birthdate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/consultation_et_id_card" android:layout_alignEnd="@+id/consultation_et_birthdate" android:layout_alignRight="@+id/consultation_et_birthdate" android:layout_marginBottom="5dp" android:layout_marginRight="10dp" app:srcCompat="@android:drawable/ic_menu_today" />
2、創(chuàng)建參數(shù)
EditText consultation_et_birthdate;//出生日期: ImageView consultation_iv_birthdate;//出生日期點(diǎn)擊
3、獲取控件
consultation_et_birthdate = (EditText) findViewById(R.id.consultation_et_birthdate); consultation_iv_birthdate = (ImageView) findViewById(R.id.consultation_iv_birthdate);
4、創(chuàng)建點(diǎn)擊事件
consultation_iv_birthdate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showDialog(DATE_DIALOG); } });
5、創(chuàng)建時(shí)間控件并獲取數(shù)據(jù)
final Calendar ca = Calendar.getInstance(); mYear = ca.get(Calendar.YEAR);//年 mMonth = ca.get(Calendar.MONTH);//月 mDay = ca.get(Calendar.DAY_OF_MONTH);//日
6、獲取點(diǎn)擊確定事件
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG: return new DatePickerDialog(this, mdateListener, mYear, mMonth, mDay); } return null; }
7、綁定數(shù)據(jù)
/** * 設(shè)置日期 綁定時(shí)間 */ private DatePickerDialog.OnDateSetListener mdateListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; consultation_et_birthdate.setText(new StringBuffer().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay).append(" ")); } };
有什么問題請留言。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自定義DataTimePicker實(shí)例代碼(日期選擇器)
- Android中的TimePickerView(時(shí)間選擇器)的用法詳解
- Android?studio實(shí)現(xiàn)日期?、時(shí)間選擇器與進(jìn)度條
- Android仿IOS10圓盤時(shí)間選擇器
- Android仿iPhone日期時(shí)間選擇器詳解
- Android日期和時(shí)間選擇器實(shí)現(xiàn)代碼
- Android自定義View仿IOS圓盤時(shí)間選擇器
- Android開發(fā)中實(shí)現(xiàn)IOS風(fēng)格底部選擇器(支持時(shí)間 日期 自定義)
- Android時(shí)間選擇器、日期選擇器實(shí)現(xiàn)代碼
- Android自定義DataTimePicker日期時(shí)間選擇器使用詳解
相關(guān)文章
Android基于OpenCV實(shí)現(xiàn)非真實(shí)渲染
非真實(shí)感渲染(Non Photorealistic Rendering,簡稱NPR),是指利用計(jì)算機(jī)模擬各種視覺藝術(shù)的繪制風(fēng)格,也用于發(fā)展新的繪制風(fēng)格。比如模擬中國畫、水彩、素描、油畫、版畫等藝術(shù)風(fēng)格。本文將講解Android基于OpenCV實(shí)現(xiàn)非真實(shí)渲染的方法2021-06-06Flutter簡潔實(shí)用的圖片編輯器的實(shí)現(xiàn)
本文主要介紹了Flutter簡潔實(shí)用的圖片編輯器的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02Android實(shí)現(xiàn)本地圖片選擇及預(yù)覽縮放效果
這篇文章主要為大家詳細(xì)介紹了Android仿春雨醫(yī)生,實(shí)現(xiàn)本地圖片選擇及預(yù)覽縮放效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03Android開發(fā)實(shí)現(xiàn)按鈕點(diǎn)擊切換背景并修改文字顏色的方法
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)按鈕點(diǎn)擊切換背景并修改文字顏色的方法,涉及Android界面布局與相關(guān)屬性設(shè)置技巧,需要的朋友可以參考下2018-01-01Android學(xué)習(xí)筆記--通過Application傳遞數(shù)據(jù)代碼示例
使用Application傳遞數(shù)據(jù)步驟如下:創(chuàng)建新class,取名MyApp,繼承android.app.Application父類,并在MyApp中定義需要保存的屬性2013-06-06接口對象的實(shí)例化在接口回調(diào)中的使用方法
下面小編就為大家?guī)硪黄涌趯ο蟮膶?shí)例化在接口回調(diào)中的使用方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Android APK文件在電腦(PC虛擬機(jī))上面運(yùn)行方法
APK是Android系統(tǒng)的發(fā)布的工程包,很多時(shí)候我們想在電腦上而非Android手機(jī)上面運(yùn)行它,需要的朋友可以了解下2012-12-12