EditText edtSelectTime;
public String time;
private int mHour, mMinute;
static final int TIME_DIALOG_ID = 1;
public int hour, minute;
@Overrideprotected void onCreate(Bundle savedInstanceState) {
edtSelectTime = (EditText) findViewById(R.id.edtSelectTimeAA);
// Assign current Date and Time Values to Variables
Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
//----------------------------------------------------------
----------------------------------------
edtSelectTime.setOnFocusChangeListener(new
View.OnFocusChangeListener() {
@Override public void onFocusChange(
View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (hasFocus) {
showDialog(TIME_DIALOG_ID);
bool = true;
}
}
});
edtSelectTime.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v) {
// Show the TimePickerDialog
showDialog(TIME_DIALOG_ID);
}
});
} // end of onCreate method()
//------------------------------------------------------
--------------------------------------------
//----------------------------------------------------
----------------------------------------------
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
return new TimePickerDialog(this,
mTimeSetListener, mHour, mMinute, false);
}//end of switch return null;
}// end of method onCreateDialog
//-------------------------------------------
-------------------------------------------------------
//------------------------------------------------
--------------------------------------------------
// Register TimePickerDialog listener
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
// the callback received when the user "sets"
//the TimePickerDialog in the dialog
public void onTimeSet(TimePicker view,
int hourOfDay, int min) {
hour = hourOfDay;
minute = min;
// Set the Selected Date in Select date Button
edtSelectTime.setText(hour + " : " + minute);
}
};
//----------------------------------------
----------------------------------------------------------
}//End of class
No comments:
Post a Comment