Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Items Are Not Shown On My List View #1

Open
hunny108 opened this issue Jun 22, 2020 · 0 comments
Open

Items Are Not Shown On My List View #1

hunny108 opened this issue Jun 22, 2020 · 0 comments

Comments

@hunny108
Copy link

//custom adapter
package com.hunny.covidtracker;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;

import java.util.List;

public class mycustomadapter extends ArrayAdapter {

private Context context;
private List countrymodelList;
public mycustomadapter( Context context, List countrymodelList ) {
super(context, R.layout.list_custom,countrymodelList);
this.context=context;
this.countrymodelList=countrymodelList;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.list_custom,null,true);
    TextView tvcountryname=view.findViewById(R.id.countryname);
    ImageView imageView=view.findViewById(R.id.imageflag);

    tvcountryname.setText(countrymodelList.get(position).getCountry());
    Glide.with(context).load(countrymodelList.get(position).getFlag()).into(imageView);
    return view;
}

}
//COUNTRY MODEL
package com.hunny.covidtracker;

public class countrymodel {

private String flag, country, cases, deaths, todayCases, todayDeaths, recovered, activeCases, critical;

public countrymodel(String url, String countryname, String flagUrl, String flag, String country, String cases, String deaths, String todayCases, String todayDeaths, String recovered) {
    this.flag = flag;
    this.country = country;
    this.cases = cases;
    this.deaths = deaths;
    this.todayCases = todayCases;
    this.todayDeaths = todayDeaths;
    this.recovered = recovered;
    this.activeCases = activeCases;
    this.critical = critical;
}

public String getFlag() {
    return flag;
}

public void setFlag(String flag) {
    this.flag = flag;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

public String getCases() {
    return cases;
}

public void setCases(String cases) {
    this.cases = cases;
}

public String getDeaths() {
    return deaths;
}

public void setDeaths(String deaths) {
    this.deaths = deaths;
}

public String getTodayCases() {
    return todayCases;
}

public void setTodayCases(String todayCases) {
    this.todayCases = todayCases;
}

public String getTodayDeaths() {
    return todayDeaths;
}

public void setTodayDeaths(String todayDeaths) {
    this.todayDeaths = todayDeaths;
}

public String getRecovered() {
    return recovered;
}

public void setRecovered(String recovered) {
    this.recovered = recovered;
}

public String getActiveCases() {
    return activeCases;
}

public void setActiveCases(String activeCases) {
    this.activeCases = activeCases;
}

public String getCritical() {
    return critical;
}

public void setCritical(String critical) {
    this.critical = critical;
}

}

//Main Activity
package com.hunny.covidtracker;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.leo.simplearcloader.SimpleArcLoader;

import org.eazegraph.lib.models.PieModel;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class effectedcountries extends AppCompatActivity {
EditText edsearch;
ListView listView;
SimpleArcLoader simpleArcLoader;
public static ListcountrymodelList=new ArrayList<>();
countrymodel countrymodel;
mycustomadapter mycustomadapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_effectedcountries2);
    edsearch=findViewById(R.id.editsearch);
    listView=findViewById(R.id.lv);
    simpleArcLoader=findViewById(R.id.loader);

    fetchdata();
}

private void fetchdata() {
    String url ="https://corona.lmao.ninja/v2/countries";
    simpleArcLoader.start();
    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                JSONArray jsonArray=new JSONArray(response);

                for(int i=0; i<jsonArray.length(); i++)
                {
                    JSONObject jsonObject= jsonArray.getJSONObject(i);

                    String countryname=jsonObject.getString("country");
                    String totalcases=jsonObject.getString("cases");
                    String todaycases=jsonObject.getString("todayCases");
                    String totaldeath=jsonObject.getString("deaths");
                    String todaydeath=jsonObject.getString("todayDeaths");
                    String recovered=jsonObject.getString("recovered");
                    String todayrecovered=jsonObject.getString("todayRecovered");
                    String activecases=jsonObject.getString("active");
                    String totalpopulation=jsonObject.getString("population");

                    JSONObject object=jsonObject.getJSONObject("countryInfo");
                    String flagUrl=object.getString("flag");
                    countrymodel =new countrymodel(flagUrl,countryname,totalcases,todaycases,totaldeath,todaydeath,recovered,todayrecovered,activecases,totalpopulation);

                }
                mycustomadapter=new mycustomadapter(effectedcountries.this,countrymodelList);
                listView.setAdapter(mycustomadapter);
                simpleArcLoader.stop();
                simpleArcLoader.setVisibility(View.GONE);








            } catch (JSONException e) {
                simpleArcLoader.stop();
                simpleArcLoader.setVisibility(View.GONE);
                e.printStackTrace();
            }


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            simpleArcLoader.stop();
            simpleArcLoader.setVisibility(View.GONE);

            Toast.makeText(effectedcountries.this,error.getMessage(), Toast.LENGTH_SHORT).show();




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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant