1

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?

Yousef
  • 54
  • 4

2 Answers2

2
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.

Irfan
  • 956
  • 9
  • 16
1

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);
Yousef
  • 54
  • 4