import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TextView;
public class MMSActivity extends Activity {
/** Called when the activity is first created. */
private DatePicker datepicker;
private TextView textview;
Calendar calendar;
int cur_year,cur_month,cur_day;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datepicker=(DatePicker)this.findViewById(R.id.DatePicker);
textview=(TextView)this.findViewById(R.id.TextView);
calendar=Calendar.getInstance();
cur_year=calendar.get(Calendar.YEAR);
cur_month=calendar.get(Calendar.MONTH+1);
cur_day=calendar.get(Calendar.DAY_OF_MONTH);
textview.setText("当前时间:"+cur_year+"年"+cur_month+"月"+cur_day+"日");
datepicker.init(cur_year,cur_month,cur_day,new MyDateChangedListener());
}
private class MyDateChangedListener implements OnDateChangedListener{
public void onDateChanged(DatePicker view,int year,int monthOfYear,int dayOfMonth){
cur_year=year;
cur_month=monthOfYear;
cur_day=dayOfMonth;
textview.setText("当前时间:"+cur_year+"年"+cur_month+"月"+cur_day+"日");
}
}
}
PS:通过日期选择器修改日期,调整后的日期用文本框视图显示。仿照书上所写,请高手帮忙
------解决方案--------------------
------解决方案--------------------