今天imma尝试开发一个简单的应用程序,它将要求用户通过按钮使用DatePickerDialog插入2个日期,然后执行查询到数据库:
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解除或等待用户输入输入然后执行查询?
答案 0 :(得分:0)
每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");
}
而且,作为一个额外的奖励,这个对话框确实是 modal (当你说"等待解雇&#34时你想要的是什么)。
答案 1 :(得分:0)
这是一个简单的对话框,我不明白为什么你不使用默认的听众:
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;
}
});