Android Studio時間選擇器的創(chuàng)建方法
本文實例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下
效果顯示:


1、創(chuàng)建xml頁面(我的項目扣下來的,有的地方會報錯要改)
<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;//出生日期點擊
3、獲取控件
consultation_et_birthdate = (EditText) findViewById(R.id.consultation_et_birthdate); consultation_iv_birthdate = (ImageView) findViewById(R.id.consultation_iv_birthdate);
4、創(chuàng)建點擊事件
consultation_iv_birthdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG);
}
});
5、創(chuàng)建時間控件并獲取數(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、獲取點擊確定事件
@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è)置日期 綁定時間
*/
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實例代碼(日期選擇器)
- Android中的TimePickerView(時間選擇器)的用法詳解
- Android?studio實現(xiàn)日期?、時間選擇器與進度條
- Android仿IOS10圓盤時間選擇器
- Android仿iPhone日期時間選擇器詳解
- Android日期和時間選擇器實現(xiàn)代碼
- Android自定義View仿IOS圓盤時間選擇器
- Android開發(fā)中實現(xiàn)IOS風(fēng)格底部選擇器(支持時間 日期 自定義)
- Android時間選擇器、日期選擇器實現(xiàn)代碼
- Android自定義DataTimePicker日期時間選擇器使用詳解
相關(guān)文章
android動態(tài)布局之動態(tài)加入TextView和ListView的方法
這篇文章主要介紹了android動態(tài)布局之動態(tài)加入TextView和ListView的方法,涉及Android動態(tài)布局的實現(xiàn)技巧,需要的朋友可以參考下2015-05-05
Android實現(xiàn)手勢滑動多點觸摸縮放平移圖片效果
這篇文章主要介紹了Android實現(xiàn)手勢滑動多點觸摸縮放平移圖片效果,實現(xiàn)圖片支持多點觸控,自由的進行縮放、平移的注意事項,感興趣的小伙伴們可以參考一下2016-02-02
Android 深入探究自定義view之流式布局FlowLayout的使用
FlowLayout(int align, int hgap, int vgap)創(chuàng)建一個新的流布局管理器,它具有指定的對齊方式以及指定的水平和垂直間隙,意思就是說從左上角開始添加原件,依次往后排,第一行擠滿了就換一行接著排2021-11-11
Android開發(fā)筆記之:如何安全中止一個自定義線程Thread的方法
本篇文章是對Android中如何安全中止一個自定義線程Thread的方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05
Android使用多線程進行網(wǎng)絡(luò)聊天室通信
這篇文章主要為大家詳細介紹了Android使用多線程進行網(wǎng)絡(luò)聊天室通信,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10

