Reputation: 111
Error messages:
There are two problems and one of them is causing the time picker not to run and the app to crash when I click on the field of the edit text which runs the time picker when clicked on.
The 'v' in v.setText... gets an error: 'The method setText(String) is undefined for the type View'. I added a cast like this: '((EditText) v).setText...' and there wasn't an error with it anymore but it is still not working
The error message I get when I put 'this' in the time picker dialog listener is: The constructor TimePickerDialog(new View.OnClickListener(){}, new TimePickerDialog.OnTimeSetListener(){}, int, int, boolean) is undefined
editTextTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
TimePickerDialog tpd = new TimePickerDialog(**this**,//same Activity Context like before
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
((EditText) v).setText(hourOfDay + ":" + minute); //You set the time for the EditText created
}
}, mHour, mMinute, true);
tpd.show();
}
});
Upvotes: 0
Views: 234
Reputation: 2408
this refers to anonymous class implementing OnClickListener. To get reference to Context (Activity) you need to provide
Activity.this
Upvotes: 0