0
當我從縱向模式切換到橫向模式時,我的timePicker不保存。當我改變方向時它會重置。 它完美的作品,但當我旋轉我的手機,由於一些奇怪的原因,我設置的時間不會留在textView。當我從縱向模式切換到橫向模式時,我的timePicker不保存
我該如何解決這個問題?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_out);
selecteddate = (TextView)findViewById(R.id.date);
AccessTime = (TextView) findViewById(R.id.time);
DisplayTime = (TextView) findViewById(R.id.time);
AccessTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calendar = Calendar.getInstance();
CalendarHour = calendar.get(Calendar.HOUR_OF_DAY);
CalendarMinute = calendar.get(Calendar.MINUTE);
timepickerdialog = new TimePickerDialog(amino_acid.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
if (hourOfDay == 0) {
hourOfDay += 12;
format = "AM";
} else if (hourOfDay == 12) {
format = "PM";
} else if (hourOfDay > 12) {
hourOfDay -= 12;
format = "PM";
} else {
format = "AM";
}
DisplayTime.setText(hourOfDay + ":" + minute + format);
}
}, CalendarHour, CalendarMinute, false);
timepickerdialog.show();
}
});
你可以請張貼一些代碼,並添加細節,哪些不工作? – Sid
發佈您的時間選擇器代碼 –
我的代碼它完美的工作,直到我旋轉我的手機 - 在橫向模式下,我已經設置的時間不會顯示在textview中。 – alma