DatePicker及其监听

xml文件:

<DatePicker
android:id="@+id/datep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

java代码:

TextView textview2;

DatePicker datep;
Calendar calendar=Calendar.getInstance();
/* (非 Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.n_layout);
datep=(DatePicker)findViewById(R.id.datep);
textview2=(TextView)findViewById(R.id.date);
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH);
int day=calendar.get(Calendar.DAY_OF_MONTH);

datep.init(year, month, day, new OnDateChangedListener(){

@Override
public void onDateChanged(DatePicker datep, int year, int month,
int day) {
// TODO 自动生成的方法存根
textview2.setText("You select date is"+year+"year"+month+"month"+day+"day");
}

});

OK。


万水千山总是情, 领个红包行不行?

觉得还可以的话记的打赏哦^.^..
原文地址:https://www.cnblogs.com/mafeng/p/4386951.html