Guest User

Untitled

a guest
Nov 7th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. @Override
  2. public void onDateChanged(DatePicker view, int year, int month, int day){
  3. String username = i.getStringExtra("us_usuario");
  4. String password = i.getStringExtra("us_clave");
  5. int Año = calendario.getYear();
  6. int Mes = calendario.getMonth()+1;
  7. int Dia = calendario.getDayOfMonth();
  8. String fecha = Año+"-"+Mes+"-"+Dia;
  9. Response.Listener<String> responseListener = new Response.Listener<String>(){
  10. @Override
  11. public void onResponse(String response){
  12. try {
  13. JSONArray jsonArray = new JSONArray(response);
  14. String hora_inicio, hora_fin, fecha, nombre, apellidos, prestacion;
  15. for (int i = 0; i < jsonArray.length(); i++) {
  16.  
  17. JSONObject jsonObject = jsonArray.getJSONObject(i);
  18. hora_inicio = jsonObject.getString("hora_inicio");
  19. hora_fin = jsonObject.getString("hora_fin");
  20. fecha = jsonObject.getString("fecha");
  21. nombre = jsonObject.getString("nombre");
  22. apellidos = jsonObject.getString("apellidos");
  23. prestacion = jsonObject.getString("prestacion");
  24.  
  25. String[] arrayRespuesta = {hora_inicio, hora_fin, nombre, apellidos, prestacion};
  26.  
  27. int[] comprobarFecha = separarFecha(fecha);
  28. TablaPacientes tabla = new TablaPacientes(Usuario.this, tablePaciente);
  29. if(comprobarFecha[0] == calendario.getYear() && comprobarFecha[1] == calendario.getMonth()+1 && comprobarFecha[2] == calendario.getDayOfMonth()){
  30. //tablePaciente.removeAllViews();
  31. tabla.agregarCabecera(R.array.tabla_pacientes);
  32. cargarTabla(tabla, arrayRespuesta);
  33. }else{
  34. tablePaciente.removeAllViews();
  35. Toast t = Toast.makeText(getApplicationContext(), "No hay pacientes para esta fecha", Toast.LENGTH_LONG);
  36. t.show();
  37. }
  38. }
  39. }catch(JSONException e){
  40. tablePaciente.removeAllViews();
  41. Toast t = Toast.makeText(getApplicationContext(), "No hay pacientes para esta fecha", Toast.LENGTH_LONG);
  42. t.show();
  43. }catch(ArrayIndexOutOfBoundsException e){
  44. tablePaciente.removeAllViews();
  45. AlertDialog.Builder builder = new AlertDialog.Builder(Usuario.this);
  46. builder.setMessage("Error de excepción en el array "+e.getLocalizedMessage())
  47. .setNegativeButton("Retry", null)
  48. .create().show();
  49. }
  50. }
  51. };
  52. RegisterRequest registerRequest = new RegisterRequest(username, password, fecha, responseListener);
  53. RequestQueue queue = Volley.newRequestQueue(Usuario.this);
  54. queue.add(registerRequest);
  55. }
Add Comment
Please, Sign In to add comment