我想做一个改变我飞行模式的应用程序。我有一个时间选择器和一个日历。现在我想设置从 tp 到 cal 的时间。我做了 2 次吐司来控制两个对象的时间。tp 的吐司显示了正确的时间(fe 13:04),但日历对象在“设置”错误时间(11:12)之后设置了时间,就像getTimeinMillis()之类的方法一样被称为所以添加了这个方法,但它仍然无法正常工作。感谢您的回答
Button b;
Button b2;
TimePicker tp;
Calendar cal;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button)(findViewById(R.id.button1));
tp = (TimePicker)(findViewById(R.id.timePicker1));
cal = Calendar.getInstance();
b2 = (Button)(findViewById(R.id.button2));
b.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(),"TimePicker "+ tp.getCurrentHour()+":"+tp.getCurrentMinute(), Toast.LENGTH_LONG).show();
cal.set(Calendar.HOUR_OF_DAY,tp.getCurrentHour());
cal.set(Calendar.MINUTE,tp.getCurrentMinute());
cal.set(Calendar.SECOND,0);
cal.getTimeInMillis();
Toast.makeText(getApplicationContext(),"Calendar "+ cal.HOUR_OF_DAY+":"+cal.MINUTE, Toast.LENGTH_LONG).show();
}
});