在Android中创建模态datepicker对话框

时间:2015-12-18 15:47:08

标签: android android-datepicker

我有这个代码工作正常,但窗口不是模态的,所以我不能在更改后得到日期。请提前给我一些建议或方法,谢谢。

以下是代码:

final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dpd = new DatePickerDialog(this,
       new DatePickerDialog.OnDateSetListener() {

           public void onDateSet(DatePicker view, int year,
                                 int monthOfYear, int dayOfMonth) {

               TextView txtDate = null;
               txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

           }

           public void onDateSet1(DatePicker view, int year,
                                  int monthOfYear, int dayOfMonth) { // TODO
               // Auto-generated
               // method stub

           }
       }, mYear, mMonth, mDay);

dpd.show();

message("message", "Mensaje", mYear + "/" + mMonth + "/" + mDay, this, context);

1 个答案:

答案 0 :(得分:1)

@WebServlet(name = "TestServlet", urlPatterns = { "/testServletName" })
public class TestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException {
        String test = request.getParameter("test");
        PrintWriter out = response.getWriter();

        try {
            System.out.println("-----> " + test + " starting");
            // Use reflection to branch out and invoke the method found in the GET method's "test" parameter
            getClass().getMethod(test, PrintWriter.class).invoke(this, response.getWriter());
            System.out.println("<----- " + test + " successful");
        } catch (Throwable x) {
            System.out.println("<----- " + test + " failed:");
        } finally {
            out.flush();
            out.close();
        }
    }

    public void testApplicationAvailable(PrintWriter pw) throws Exception {
        System.out.prinln("Application and test servlet available");
    }

    public void testThatFails(PrintWriter pw) throws Exception {
        throw new Exception("This test will fail");
    }
}