

日期选择对话框
.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >
<Button android:id="@+id/mybut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="设置日期"/> <TextView android:id="@+id/mytxt" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</RelativeLayout>
.java public class MainActivity extends Activity { private Button mybut=null; private TextView txt=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.mybut=(Button) super.findViewById(R.id.mybut); this.txt=(TextView) super.findViewById(R.id.mytxt); this.mybut.setOnClickListener(new OnClickListenerImp()); } public class OnClickListenerImp implements OnClickListener{
public void onClick(View arg0) { Dialog dialog=new DatePickerDialog(MainActivity.this,new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { MainActivity.this.txt.setText("修改的日期为:"+year+"年"+(monthOfYear+1)+"月"+dayOfMonth+"日"); } },1990,8,16);//表示默认的年月日 dialog.show(); } }
}