app/src/main/java/com/mohammadKZ/CoronaVirus_COVID19_statistics/fragments/CountryFragment.java
private void ApiRequest() {
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url_api, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    JSONArray jsonArray = new JSONArray(response);

                    Log.e("lentgh", "aa  " + jsonArray.length());

                    GsonBuilder gsonBuilder = new GsonBuilder();
                    Gson gson = gsonBuilder.create();

                    for (int i = 0; i < jsonArray.length(); i++) {
                        Country country = gson.fromJson(String.valueOf(jsonArray.getJSONObject(i)), Country.class);
                        country.setFlag(jsonArray.getJSONObject(i).getJSONObject("countryInfo").getString("flag"));
                        countries.add(country);
                    }

                    System.out.println();
                    spin_kit.setVisibility(View.GONE);
                    connect.setVisibility(View.GONE);
                    constraintLayout.setVisibility(View.VISIBLE);
                    Spinner(countries);


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

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                try {

                    Log.d("Error", "connection failed" + " ");
                    Toast.makeText(getContext(), "check the internet connection...", Toast.LENGTH_SHORT).show();
                    alertDialog();// alert for connection
                } catch (Exception e) {
                    e.getMessage();
                }

            }
        });

        requestQueue.add(stringRequest);
    }
// api request and get the info
api request and get the info
api request and get the info
private void ApiRequest() {
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url_api, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    JSONArray jsonArray = new JSONArray(response);
                    Log.e("lentgh", "aa  " + jsonArray.length());
                    GsonBuilder gsonBuilder = new GsonBuilder();
                    Gson gson = gsonBuilder.create();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        Country country = gson.fromJson(String.valueOf(jsonArray.getJSONObject(i)), Country.class);
                        country.setFlag(jsonArray.getJSONObject(i).getJSONObject("countryInfo").getString("flag"));
                        countries.add(country);
                    }
                    System.out.println();
                    spin_kit.setVisibility(View.GONE);
                    connect.setVisibility(View.GONE);
                    constraintLayout.setVisibility(View.VISIBLE);
                    Spinner(countries);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                try {
                    Log.d("Error", "connection failed" + " ");
                    Toast.makeText(getContext(), "check the internet connection...", Toast.LENGTH_SHORT).show();
                    alertDialog();
                } catch (Exception e) {
                    e.getMessage();
                }
            }
        });
        requestQueue.add(stringRequest);
    }
private void ApiRequest ( ) { StringRequest stringRequest = new StringRequest ( Request . Method . GET , url_api , new Response . Listener < String > ( ) { @ Override public void onResponse ( String response ) { try { JSONArray jsonArray = new JSONArray ( response ) ; Log . e ( "lentgh" , "aa  " + jsonArray . length ( ) ) ; GsonBuilder gsonBuilder = new GsonBuilder ( ) ; Gson gson = gsonBuilder . create ( ) ; for ( int i = 0 ; i < jsonArray . length ( ) ; i ++ ) { Country country = gson . fromJson ( String . valueOf ( jsonArray . getJSONObject ( i ) ) , Country . class ) ; country . setFlag ( jsonArray . getJSONObject ( i ) . getJSONObject ( "countryInfo" ) . getString ( "flag" ) ) ; countries . add ( country ) ; } System . out . println ( ) ; spin_kit . setVisibility ( View . GONE ) ; connect . setVisibility ( View . GONE ) ; constraintLayout . setVisibility ( View . VISIBLE ) ; Spinner ( countries ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; } } } , new Response . ErrorListener ( ) { @ Override public void onErrorResponse ( VolleyError error ) { try { Log . d ( "Error" , "connection failed" + " " ) ; Toast . makeText ( getContext ( ) , "check the internet connection..." , Toast . LENGTH_SHORT ) . show ( ) ; alertDialog ( ) ; } catch ( Exception e ) { e . getMessage ( ) ; } } } ) ; requestQueue . add ( stringRequest ) ; }
api request and get the info
api request and get the info
// alert for connection