<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:orientation=“vertical”>
<TextView android:id=“@+id/dateDisplay”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“”/>
<Button android:id=“@+id/pickDate”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“Change the date”/>
<DatePicker android:id=“@+id/datePicker”
android:foreground=“@android:color/background_dark”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:longClickable=“true”/>
HelloDatePickerActivity.java
package learn.test;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
public class HelloDatePickerActivity extends Activity {
/** Called when the activity is first created. */
private TextView mDateDisplay;
private Button mPickDate;
private int mYear;
private int mMonth;
private int mDay;
//该常量用于标识DatePickerDialog
static final int DATE_DIALOG_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// capture our View elements
mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
mPickDate = (Button) findViewById(R.id.pickDate);
// add a click listener to the button
//这里用的是匿名内部类,OnClickListener只是一个接口, 用它来绑定监听器,
mPickDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 些方法会调用 protected Dialog onCreateDialog(int id)
showDialog(DATE_DIALOG_ID);
}
});
// get the current date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
// display the current date (this method is below)
updateDisplay();
}
private void updateDisplay() {
mDateDisplay.setText(new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append(“-”).append(mDay).append(“-”)
.append(mYear).append(" "));
}
//这里使用的是匿名内部类,OnDateSetListener只是这个类里面的一个接口,必须实现onDateSet这个类。
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();
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
}
return null;
}
}
例二:结果如图:
main.xml布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:orientation=“vertical”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”>
<DatePicker android:id=“@+id/datePicker”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_gravity=“center_horizontal”/>
<EditText android:id=“@+id/dateEt”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:cursorVisible=“false”
android:editable=“false”/>
<TimePicker android:id=“@+id/timePicker”
android:layout_width=“wrap_content”
建议
当我们出去找工作,或者准备找工作的时候,我们一定要想,我面试的目标是什么,我自己的技术栈有哪些,近期能掌握的有哪些,我的哪些短板 ,列出来,有计划的去完成,别看前两天掘金一些大佬在驳来驳去 ,他们的观点是他们的,不要因为他们的观点,膨胀了自己,影响自己的学习节奏。基础很大程度决定你自己技术层次的厚度,你再熟练框架也好,也会比你便宜的,性价比高的替代,很现实的问题但也要有危机意识,当我们年级大了,有哪些亮点,与比我们经历更旺盛的年轻小工程师,竞争。
-
无论你现在水平怎么样一定要 持续学习 没有鸡汤,别人看起来的毫不费力,其实费了很大力,这四个字就是我的建议!!!!!!!!!
-
准备想说怎么样写简历,想象算了,我觉得,技术就是你最好的简历
-
我希望每一个努力生活的it工程师,都会得到自己想要的,因为我们很辛苦,我们应得的。
-
有什么问题想交流,欢迎给我私信,欢迎评论
【附】相关架构及资料
内含往期Android高级架构资料、源码、笔记、视频。高级UI、性能优化、架构师课程、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter全方面的Android进阶实践技术
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
img-MkSXNFkN-1715316225115)]
[外链图片转存中…(img-lX91QIHI-1715316225116)]
内含往期Android高级架构资料、源码、笔记、视频。高级UI、性能优化、架构师课程、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter全方面的Android进阶实践技术
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!