I add a onClick method to various EditTexts. It opens a DialogFragment.
public void eligeHora (View view){
TimePickerFragment newFragment = new TimePickerFragment();
newFragment.show(getFragmentManager(),"hadshads");
}
Now, inside the DialogFragment class I want to get the id of THE EditText clicked (there are many). In this example I get the EditText with the id "hora", but I want it "generic".
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
//Create and return a new instance of TimePickerDialog
return new TimePickerDialog(getActivity(),this, 0, 0,
true);
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
//Do something with the user chosen time
//Get reference of host activity (XML Layout File) TextView widget
EditText tv = getActivity().findViewById(R.id.hora);
tv.setText(String.valueOf(hourOfDay)+ " : " +
String.valueOf(minute) + "\n");
}
}
How do I get the id of the view clicked to open the DialogFragment? In the example I used the id of a specific view (R.id.hora), but I want to be able to use this fragment with all the views that have the method eligeHora.