さまざまなボタンから呼び出すことができるtimePickerダイアログがあります。ダイアログの呼び出し元のIDを渡すにはどうすればよいですか?
これは関連するコードです:
//Time picker
private int pHour;
private int pMinute;
static final int TIME_DIALOG_ID = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** Get the current time */
final Calendar cal = Calendar.getInstance();
pHour = cal.get(Calendar.HOUR_OF_DAY);
pMinute = cal.get(Calendar.MINUTE);
}
ボタンからのクリックイベント:
public void onClick(View v) {
// Here I should pass the v.getId() to the dialog
showDialog(TIME_DIALOG_ID);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
return new TimePickerDialog(this,
mTimeSetListener, pHour, pMinute, false);
}
return null;
}
/** Callback received when the user "picks" a time in the dialog */
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
pHour = hourOfDay;
pMinute = minute;
//Here I should know from which v.getId() the dialog was called
}
};
ありがとう!