修改时间后,Title就是不变,大神搭救哦!
package com.example.dateortime;
import java.util.Calendar;
import javax.security.auth.PrivateCredentialPermission;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TimePicker timePicker;
final DatePicker datePicker;
Calendar cal;
int year;
int month;
int day;
int hour;
int minute;
//获取日历的对象
cal = Calendar.getInstance();
//获取年月日时分秒的信息
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH)+1;
day = cal.get(Calendar.DAY_OF_MONTH);
hour = cal.get(Calendar.HOUR_OF_DAY);
minute = cal.get(Calendar.MINUTE);
setTitle(year+"-"+month+"-"+day+" "+hour+":"+minute);
datePicker = (DatePicker) findViewById(R.id.datePicker);
timePicker = (TimePicker) findViewById(R.id.timePicker);
//
datePicker.init(year, cal.get(Calendar.MONTH), day, new OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year1, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
setTitle(year1+"-"+monthOfYear+"-"+dayOfMonth);
//这里测试toast都可以显示修改后日期的,但是setTitle就是没用,咋破?
String text = year1+"-"+(monthOfYear+1)+"-"+dayOfMonth;
Toast.makeText(datePicker.getContext(), text, 5).show();
}
});
timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker arg0, int hourOfDay, int minute1) {
// TODO Auto-generated method stub
setTitle(hourOfDay+":"+minute1);
}
});
}
}