Search code examples
androidarraysjsonobjectlistview

How can I filter JSON listview


What I want is to show in the list is the String that equals(London) in:

String location =  respons.getString("location"); 

if it equals to Manchester, I don't want it to be in the list:

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

    JSONObject respons =jsonArray.getJSONObject(i);  
    String id = respons.getString("id");
    String location =  respons.getString("location");
    String info = respons.getString("name");
    String img = respons.getString("img");

    listitmes.add(new Listitme(id, location, info, img));
    listAllItme();

}

Solution

  • JSONObject respons =jsonArray.getJSONObject(i);
    // do your test hire if respons.getString("location") equlas the String "manchestar"
    if(respons.getString("location").equlas("manchestar")){
        String id=respons.getString("id");
        String info=respons.getString("name");
        String img=respons.getString("img");
        listitmes.add(new Listitme(id,location,info,img));
        listAllItme();
    }