Guest User

Untitled

a guest
Nov 16th, 2017
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. public void cogerFechas(){
  2. String username = i.getStringExtra("us_usuario");
  3. String password = i.getStringExtra("us_clave");
  4.  
  5. Response.Listener<String> responseListener = new Response.Listener<String>(){
  6. @Override
  7. public void onResponse(String response){
  8. try {
  9. JSONArray jsonArray = new JSONArray(response);
  10. String fechaAux;
  11. for(int x=0; x<jsonArray.length(); x++){
  12. JSONObject jsonObject = jsonArray.getJSONObject(x);
  13. fechaAux = jsonObject.getString("fecha");
  14. arrayIntFechas = new ArrayList<>();
  15. arrayIntFechas.add(separarFecha(fechaAux));
  16. }
  17. }catch(JSONException e){
  18. AlertDialog.Builder builder = new AlertDialog.Builder(Usuario.this);
  19. builder.setMessage(e.getMessage())
  20. .setNegativeButton("Retry", null)
  21. .create().show();
  22. }catch(ArrayIndexOutOfBoundsException e){
  23. AlertDialog.Builder builder = new AlertDialog.Builder(Usuario.this);
  24. builder.setMessage("Error de excepción en el array "+e.getLocalizedMessage())
  25. .setNegativeButton("Retry", null)
  26. .create().show();
  27. }
  28. if(!arrayIntFechas.isEmpty()){
  29.  
  30. Toast t = Toast.makeText(getApplicationContext(), "SOI IO, EL COCU", Toast.LENGTH_SHORT);
  31. t.show();
  32. }else if(arrayIntFechas.isEmpty()){
  33.  
  34. }
  35. }
  36. };
  37. FechasRequest fechasRequest = new FechasRequest(username, password, responseListener);
  38. RequestQueue queue = Volley.newRequestQueue(Usuario.this);
  39. queue.add(fechasRequest);
  40. }
  41.  
  42. public int[] separarFecha(String fecha){
  43. String[] añoMesDia = fecha.split("-");
  44. String añoS = añoMesDia[0], mesS = añoMesDia[1], diaS = añoMesDia[2];
  45. int año = Integer.parseInt(añoS), mes = Integer.parseInt(mesS), dia =
  46. Integer.parseInt(diaS);
  47. int [] arrFecha = {año, mes, dia};
  48. return arrFecha;
  49. }
Add Comment
Please, Sign In to add comment