我正在使用XML中的Lolipop Material Designing实现Time Picker。 OnTimeChangedListener在nexus设备上工作正常但是当我在具有OS 5.0.2的Motorola手机上测试它时OnTimeChangedListener没有启动。任何人都可以帮我解决它。这是我的java文件。
公共类MainActivity扩展了Activity实现OnTimeChangedListener {
/** Private members of the class */
private TextView displayTime;
private Button pickTime;
private int pHour;
private int pMinute;
TimePicker picker;
private String am_pm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picker = (TimePicker) findViewById(R.id.time);
final Calendar c = Calendar.getInstance();
Calendar mcurrentDate = Calendar.getInstance();
int mHour = mcurrentDate.get(Calendar.HOUR_OF_DAY);
int mMinute = mcurrentDate.get(Calendar.MINUTE);
picker.setOnTimeChangedListener(this);
}
OnTimeChangedListener listener = new OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
pHour = hourOfDay;
pMinute = minute;
System.out.println("pHour" + pHour);
System.out.println("pMinute" + pMinute);
}
};
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
pHour = hourOfDay;
pMinute = minute;
System.out.println("pHour" + pHour);
System.out.println("pMinute" + pMinute);
}
}