public class Activity_2 extends Activity implements OnClickListener { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
findViewById(R.id.textView1).setOnClickListener(this);
findViewById(R.id.textView2).setOnClickListener(this);
} @Override
public void onClick(View v) {
final TextView txtview = (TextView) v;
String str = txtview.getText().toString();
Pattern pattern = Pattern.compile("^(\\d+)年(\\d+)月(\\d+)日$");
Matcher match = pattern.matcher(str);
int year = 1990, month = 0, day = 1;
if (match.find()) {
year = Integer.valueOf(match.group(1));
month = Integer.valueOf(match.group(2))-1;
day = Integer.valueOf(match.group(3));
}
DatePickerDialog Dt1 = new DatePickerDialog(this,
new OnDateSetListener() { @Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
txtview.setText(year + "年" + (monthOfYear+1) + "月"
+ dayOfMonth + "日");
}
}, year, month, day);
Dt1.show();
}}