今天,imma试图开发一个简单的应用程序,它将要求用户通过按钮使用DatePickerDialog插入两个日期,然后在数据库中执行查询:
Button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
Da = new DatePickerDialog(MainActivity.this, DADateSetListener, 2014, 8, 24);
Da.show();
Da.setTitle("Date FROM");
A = new DatePickerDialog(MainActivity.this, ADateSetListener, 2014, 10, 24);
A.show();
A.setTitle("Date TO");
//Erase the List View
List.setAdapter(null);
prepareProgressBar();
query();
}
});我唯一的问题是:我如何等待DatePickerDialog执行,消除或等待用户输入输入,然后执行查询?
发布于 2014-09-25 03:42:09
每个the docs
我们建议您使用
DialogFragment来承载每个时间或日期选择器。
文档包括一个扩展DialogFragment (位于here)的示例类:
public static class TimePickerFragment 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()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
}
}您可以像这样显示它(同样,来自the docs的代码):
public void showTimePickerDialog(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker");
}而且,作为一个额外的好处,这个对话框确实是的(当你说“等待解除”时,你想要的就是这个)。
发布于 2014-09-25 03:45:44
这是一个简单的对话框,我不明白你为什么不使用默认的监听器:
DatePickerDialog dpd;
dpd.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// Handle dismiss
}
});
dpd.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
// Handle clicks
return false;
}
});https://stackoverflow.com/questions/26025021
复制相似问题