我使用 onTimeChanged 侦听器从 timepicker 接收,但是当我尝试在 textview 中显示它时,我收到错误消息“无法从 TextView 类型对非静态方法 setText(CharSequence) 进行静态引用”,即使我声明了全局变量。我在 onCreate 方法中使用监听器。
TimePicker.OnTimeChangedListener timePickerListener = new TimePicker.OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int selectedHour, int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
StringBuilder sb=new StringBuilder();
sb.append(hour).append(":").append(minute);
str=sb.toString();
TextView.setText(str);
}