1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | btn.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { // check if this form is Valid if (!CheckForm()) { AlertDialog.Builder bd = new AlertDialog.Builder(ll.getContext()); AlertDialog ad = bd.create(); ad.setTitle("Error"); ad.setMessage("Please enter all required (*) fields"); ad.show(); return; } if (theForm.getSubmitTo().equals("loopback")) { // just display the results to the screen String formResults = theForm.getFormattedResults(); Log.i(tag,formResults); AlertDialog.Builder bd = new AlertDialog.Builder(ll.getContext()); AlertDialog ad = bd.create(); ad.setTitle("Results"); ad.setMessage(formResults); ad.show(); return; } else { if (!SubmitForm()) { AlertDialog.Builder bd = new AlertDialog.Builder(ll.getContext()); AlertDialog ad = bd.create(); ad.setTitle("Error"); ad.setMessage("Error submitting form"); ad.show(); return; } } } } ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | private boolean CheckForm() { try { int i; boolean good = true; for (i=0;i<theForm.fields.size();i++) { String fieldValue = (String) theForm.fields.elementAt(i).getData(); Log.i(tag,theForm.fields.elementAt(i) .getName() + " is [" + fieldValue + "]"); if (theForm.fields.elementAt(i).isRequired()) { if (fieldValue == null) { good = false; } else { if (fieldValue.trim().length() == 0) { good = false; } } } } return good; } catch(Exception e) { Log.e(tag,"Error in CheckForm()::" + e.getMessage()); e.printStackTrace(); return false; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | private boolean SubmitForm() { try { boolean ok = true; this.progressDialog = ProgressDialog.show(this, theForm.getFormName(), "Saving Form Data", true,false); this.progressHandler = new Handler() { @Override public void handleMessage(Message msg) { // process incoming messages here switch (msg.what) { case 0: // update progress bar progressDialog.setMessage("" + (String) msg.obj); break; case 1: progressDialog.cancel(); finish(); break; case 2: progressDialog.cancel(); break; } super.handleMessage(msg); } }; Thread workthread = new Thread(new TransmitFormData(theForm)); workthread.start(); return ok; } catch (Exception e) { Log.e(tag,"Error in SubmitForm()::" + e.getMessage()); e.printStackTrace(); // tell user that the submission failed.... Message msg = new Message(); msg.what = 1; this.progressHandler.sendMessage(msg); return false; } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |