Reputation: 54
I'm using a TimePickerDialog
in my application, I use a hint
for the EditText (through which time is set), but once the user sets time in the TimePickerDialog the hint goes away and the time selected replaces it.
I want the present time (hour and minute) to be displayed in the EditText before the user sets the time, How can I do that?
Upvotes: 1
Views: 169
Reputation: 54
I added the following code to my project and it worked:
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
String time = timeFormat.format(Calendar.getInstance().getTime());
editText.setText(time);
Upvotes: 1
Reputation: 956
get the current time and set it to the edit text.
EditText editText = (EditText) findViewById(R.id.editText);
Date currentDate = new Date(System.currentTimeMillis());
currentDate.setText(currentDate.toString());
and if you want to perform any actions on edit text click, perform on click like opening a date picker and on selection set seletted date again to the editText. Hope it helps.
Upvotes: 2