大家好:
想請教一下
我用android TimePickerDialog功能
我是用一個edittext 按下去後顯示TimePickerDialog
可以讓我選時間,但他每個時間都能選.....
我希望使用者只能選特定時間
例如:時間只有8-17時可選,超過就無法選,也不會顯示
分鐘只有0或30其他數字消失或是按到其他數字指針會自動移到0之類的
time2=(EditText)findViewById(R.id.time2);
time2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
showtime2();
}
}
});
.......
time2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
showtime2();
}
}
});
private void showtime2() {
Calendar c = Calendar.getInstance();
new TimePickerDialog(Off.this, R.style.DatePickBackgroundColor2, new
TimePickerDialog.OnTimeSetListener(){
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String tmp="",tmp2="";
if(hourOfDay<10){tmp="0"+hourOfDay;}else tmp=""+hourOfDay;
if(minute<10){tmp2="0"+minute;}else tmp2=""+minute;
time2.setText(tmp + ":" + tmp2);
}
}, c.get(Calendar.HOUR), c.get(Calendar.MINUTE), false).show();
}
謝謝大家