Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class dayActivities extends AppCompatActivity {
- private RecyclerView mRecyclerView;
- private JsonManager json;
- ArrayList<Tarea> list;
- RequestQueue requestQueue;
- String url="http://186.16.12.200:3000/agenda1";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_day_activities);
- Bundle b = getIntent().getExtras();
- String date = b.getString("fecha");
- setTitle(getDate(date));
- requestQueue= Volley.newRequestQueue(getApplicationContext());;
- mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
- mRecyclerView.setHasFixedSize(true);
- LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
- layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
- mRecyclerView.setLayoutManager(layoutManager);
- this.getData(date);
- }
- public void getData(String date){
- list=new ArrayList<Tarea>();
- JsonArrayRequest arrReq = new JsonArrayRequest(Request.Method.GET, url + "?fecha=" + date,null,
- new Response.Listener<JSONArray>() {
- @Override
- public void onResponse(JSONArray response) {
- if (response.length() > 0) {
- // The user does have repos, so let's loop through them all.
- for (int i = 0; i < response.length(); i++) {
- try {
- // For each repo, add a new line to our repo list.
- JSONObject jsonObj = response.getJSONObject(i);
- Integer id = (Integer) jsonObj.get("id");
- String actividad = jsonObj.get("actividad").toString();
- String fecha = jsonObj.get("fecha").toString();
- String inicio = jsonObj.get("horaInicio").toString();
- String fin = jsonObj.get("horaFin").toString();
- list.add(new Tarea(id,actividad,fecha,inicio,fin));
- } catch (JSONException e) {
- // If there is an error then output this to the logs.
- Log.e("Volley", "Invalid JSON Object.");
- }
- }
- mRecyclerView.setAdapter(new Adaptador(list));
- } else {
- // The user didn't have any repos.
- Log.e("Volley", "Not found");
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.e("Volley", error.toString());
- error.printStackTrace();
- }
- });
- // Add the request we just defined to our request queue.
- // The request queue will automatically handle the request as soon as it can.
- requestQueue.add(arrReq);
- }
- public String getDate(String fecha){
- String meses[]={"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto,","Septiembre","Octubre","Noviembre","Diciembre"};
- return fecha.substring(6)+" de "+meses[Integer.parseInt(fecha.substring(4,6))-1]+" del "+fecha.substring(0,4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement