new request to an api

0

Very good I do not know if my question is well formulated. I will comment .. I'm doing an android app where I have a RecyclerView and Cardsviews. where I intend to show the results of football matches. obtaining the data of an API. So far everything is going well, the problem I have is that the Json only shows me this information .. example

"fixtures": [
{
  "_links": {
    "self": {
      "href": "http://api.football-data.org/v1/fixtures/165080"
    },
    "competition": {
      "href": "http://api.football-data.org/v1/competitions/467"
    },
    "homeTeam": {
      "href": "http://api.football-data.org/v1/teams/818"
    },
    "awayTeam": {
      "href": "http://api.football-data.org/v1/teams/766"
    }
  },
  "date": "2018-06-19T12:00:00Z",
  "status": "TIMED",
  "matchday": 1,
  "homeTeamName": "Colombia",
  "awayTeamName": "Japan",
  "result": {
    "goalsHomeTeam": null,
    "goalsAwayTeam": null
  },
  "odds": null
},

with this I show the names of the teams, the date that will be or was the match, the goals of each one .. up to here well. I've already started it. but the JSON shows me other URLs. of each team in specific. for example the homeTeam team.

"_links": {
"self": {
  "href": "http://api.football-data.org/v1/teams/818"
},
"fixtures": {
  "href": "http://api.football-data.org/v1/teams/818/fixtures"
},
"players": {
  "href": "http://api.football-data.org/v1/teams/818/players"
}
 },
"name": "Colombia",
"code": "COL",
"shortName": null,
"squadMarketValue": null,
"crestUrl": 
"https://upload.wikimedia.org/wikipedia/commons/2/21/Flag_of_Colombia.svg"
}

I would like to know what is the method to reapply this URL and implement it in my app I am interested because it contains an iten called "crestUrl" which contains a url of an image and want to place it in the app. I do not know if they understand me I think so ... thanks for your attention. here my code ..

Data Json request method

 private void LoadRecyclerViewData(){
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Loading data...");
    progressDialog.show();


    StringRequest stringRequest = new StringRequest(Request.Method.GET,
            URL_DATA,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {

                    progressDialog.dismiss();

                    try {
                        JSONObject jsonObject = new JSONObject(s);

                        JSONArray  array = jsonObject.getJSONArray("fixtures");

                        for (int i = 0; i<array.length(); i++){
                            JSONObject o = array.getJSONObject(i);
                            ListItem item = new ListItem(
                                    o.getString("homeTeamName"),
                                    o.getString("awayTeamName"),
                                    o.getJSONObject("result").getString("goalsHomeTeam"),
                                    o.getJSONObject("result").getString("goalsAwayTeam"),
                                    o.getString("date"),
                                    o.getString("status")
                            );
                            listItems.add(item);
                        }

                        adapter = new MyAdapter(listItems, getApplicationContext());

                        recyclerView.setAdapter(adapter);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },

            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    progressDialog.dismiss();
                    Toast.makeText(getApplicationContext(), error.getMessage(),Toast.LENGTH_LONG).show();

                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

adapter:

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    final ListItem listItem = listItems.get(position);

    holder.textViewhome.setText(listItem.getHome());
    holder.textViewaway.setText(listItem.getAway());

    holder.textViewresulhome.setText(listItem.getResulhome());
    holder.textViewresulaway.setText(listItem.getResulaway());

    holder.textViewdate.setText(listItem.getDate());
    holder.textViewstatus.setText(listItem.getStatus());

Thank you for your attention:)

    
asked by Andres Gonzalez 19.06.2018 в 05:26
source

0 answers