DatePicker
一、Datapicker
activity示例代码:
public class DatePickerDIalogDemoActivity extends Activity {
private Button btn1=null;
private TextView tv1=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1=(Button)findViewById(R.id.btn);
btn1.setOnClickListener(new Btn());
tv1=(TextView)findViewById(R.id.tv1);
}
//创建监听器
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch(id){
case 1:{
return new DatePickerDialog(this,dateP,2011,8,15);
}
}
return null;
}
//按钮监听器
class Btn implements OnClickListener{
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(1);
}
}
//创建监听器类
DatePickerDialog.OnDateSetListener dateP=new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
tv1.setText(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}
};
}