Here is my code for a TimePicker class I have created
picker.java
package com.example.abhijeet.todo;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.EditText;
import android.widget.TimePicker;
import java.util.Calendar;
/**
* Created by Abhijeet on 9/6/2017.
*/
public class Picker extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
//Creating a View object because this class do not extend from activity class so no findviewbyid() method is present
View v =View.inflate(* ? *,R.layout.activity_editor,null); //HERE
//Displaying the user selected time on the Edit Text view
EditText edittime = (EditText) v.findViewById(R.id.time_editext_field);
}
}
I am trying to show the time selected via the picker in a edit text box. I am not able to find the right context for the argument.
I have read the answer here which explains about the different usages of the context, but that does not seem to help me.
Thank for the help in Advance.