<?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" >
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click here for change"/>
</LinearLayout>
/////////////////////////////////////////
package date_program.day_program;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
public class SampleActivity extends Activity {
/** Called when the activity is first created. */
private int year,month,day;
private TextView tvdisplay;
private Button btpress;
static final int DATE_DIALOG_ID=999;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvdisplay=(TextView)findViewById(R.id.textview1);
btpress=(Button)findViewById(R.id.button1);
tpress.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_ID);
}
});
final Calendar c=Calendar.getInstance();
year=c.get(Calendar.YEAR);
month=c.get(Calendar.MONTH);
day=c.get(Calendar.DAY_OF_MONTH);
Updatedisplay();
}
protected Dialog OnCreateDialog(int Id) {
switch(Id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,datepicking,year,month,day);
}
return null;
}
private DatePickerDialog.OnDateSetListener datepicking =new
DatePickerDialog.OnDateSetListener(){
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
year=arg1;
month=arg2;
day=arg3;
Updatedisplay();}
};
private void Updatedisplay() {
tvdisplay.setText(new StringBuilder().append("Date-").
append(month+1).append("/").append(day).append("/").append(year));
}
}
在android中为什么我不能用这个程序改变当前日期,即点击按钮后没有出现对话框,这个程序有什么错误请详细解释。感谢您的时间和考虑。