您好,我是 android 开发的新手,我正在开发一个应用程序,它需要从 timePicker 获取小时和分钟,所以我确实喜欢这样来获取它:
public class MainActivity extends Activity {
TimePicker timePicker;
int hour, changedHour;
int minute, changedMinute;
TextView tv, tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
tv1 = (TextView) findViewById(R.id.textView2);
timePicker = (TimePicker) findViewById(R.id.timePicker1);
setCurrentTime();
timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker arg0, int hourOfDay,
int minuteOf) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Time set!",
Toast.LENGTH_SHORT).show();
changedHour = hourOfDay;
changedMinute = minuteOf;
tv.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
}
});
tv1.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
}
public void setCurrentTime() {
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
timePicker.setCurrentHour(hour);
timePicker.setCurrentMinute(minute);
}`
问题就在这里
changedHour = hourOfDay;
changedMinute = minuteOf;
tv.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
我得到了更改的时间,并且当我尝试使用变量时,我将其设置为小时将在hourOfDay = changedHour
并且现在在方法之外的分钟相同,问题是它设置为 0 HERE
tv1.setText("Hour of Day is " + changedHour + " and Minute is "
+ changedMinute);
请帮我!