标签:android style blog http color io os 使用 java
1. main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" > </DatePicker> </LinearLayout>
2. firseAcitivy.java
public class firstActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); DatePicker myDatePicker=(DatePicker)findViewById(R.id.datePicker1); //获取对象 OnDateChangedListener onDateChangedListener = new DatePicker.OnDateChangedListener() { //设置监听器 @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "当前日期为:"+year+"年"+(monthOfYear+1)+"月"+dayOfMonth+"日", Toast.LENGTH_LONG).show(); //显示更改后的日期 } }; myDatePicker.init(2010, 1, 1, onDateChangedListener); //初始化日期选择控件 显示月份 = 设置月份+1 myDatePicker.updateDate(2012, 11, 31); //更新日期 } }
3. 效果图
标签:android style blog http color io os 使用 java
原文地址:http://www.cnblogs.com/SM-t/p/3980962.html