gpt4 book ai didi

android - timePickerFragment 取消按钮上的监听器?

转载 作者:行者123 更新时间:2023-11-29 18:09:00 26 4
gpt4 key购买 nike

我会使用 TimePickerFragment 来设置时间,它可以完美地工作。

我只想在用户点击“取消”按钮时执行一个操作。

不幸的是,到目前为止我还没有找到如何去做。

这是我的代码:

创建对话框:

public void changeTime(int position) {
df = new TimePickerFragment();
df.setActivity(activity);
df.show(getSupportFragmentManager(), "timePicker");

positionItemTime = position;

}

当用户点击“设置”时执行一个 Action :

public void setTime(int hourOfDay, int minute) {

visibleCursorNotes.moveToPosition(positionItemTime);

int idSelectedRow = visibleCursorNotes.getInt(visibleCursorNotes.getColumnIndex("_id"));

String content = visibleCursorNotes.getString(visibleCursorNotes.getColumnIndex("content_note"));

String minuteString = "";
String hourOfDayString = "";

minuteString = "" + minute;
hourOfDayString = "" + hourOfDay;

if (minute < 10){
minuteString = "0" + minuteString;
}

if (hourOfDay < 10){
hourOfDayString = "0" + hourOfDayString;
}

String time = "" + hourOfDayString + ":" + minuteString ;

if (content.equals("")){
content = "add note ...";
}

nds.updateNote(idSelectedRow, content, time);

visibleCursorNotes = nds.getCursorUpdatedDatabaseForADate(visibleDate);
updateData();

visibleListView.setSelection(positionItemTime);

activity.managerOfSound("write note");

}

总结:想捕捉点击取消按钮事件来执行一个 Action 。

谢谢。

最佳答案

这是基于重写的解决方案:

public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener,
TimePickerDialog.OnDismissListener{

@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()));
}


public void onDismiss(DialogInterface dialog){

System.out.println("oui c'est très bon !");

}

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
System.out.println("voila");
}
}

技巧的主要部分是实现 TimePickerDialog.OnDismissListener,然后实现函数。谢谢大家。

关于android - timePickerFragment 取消按钮上的监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11788843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com