-1

I want to show when clicking on an editText a timePicker and it gives me this error in the constructor, it sure is a silly mistake but I can not solve it, can someone help me?

hIni.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                int hour = calendario.get(Calendar.HOUR_OF_DAY);
                int minute = calendario.get(Calendar.MINUTE);

                final TimePickerDialog.OnTimeSetListener time = new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int hour, int minute) {
                        calendario.set(Calendar.HOUR_OF_DAY, hour);
                        calendario.set(Calendar.MINUTE, minute);
                        String horaInicio = String.valueOf(hour) + ":" + String.valueOf(minute);
                        hIni.setText(horaInicio);
                    }
                };
                new TimePickerDialog(Nuevo4.this,time, hour, minute).show();
            }
        });

I get this compilation error:

Cannot resolve constructor (TimePickerDialog'Nuevo4, android.app.TimePickerDialog.OnTimeSetListener, int, int)

Thank you

midlab
  • 189
  • 1
  • 6

2 Answers2

2

You should add a boolean after minute, whether this is a 24 hour view or AM/PM. So you will have something like this: new TimePickerDialog(Nuevo4.this,time, hour, minute, true).show(); hope it helps!

Alexandru
  • 98
  • 8
2

That's because you're not passing the correct arguments. There are two available constructors:

TimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView)

Creates a new time picker dialog.

and

TimePickerDialog(Context context, int themeResId, TimePickerDialog.OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView)

Creates a new time picker dialog with the specified theme.

You could use the first one, and pass in the listener and the boolean in the end to define whether this is a 24 hour view or AM/PM.

new TimePickerDialog(Nuevo4.this,time, hour, minute, true).show();

Check the developers guide here

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39