Android 如何从列表视图中删除来自服务器的重复项

Android 如何从列表视图中删除来自服务器的重复项,android,Android,我对安卓有点陌生。下面是我的代码。我在这里使用了一个列表,我获取楼层编号,但得到重复的值 我将重复的值作为json数据存储在服务器中 请帮我从列表中删除重复的项目。谢谢大家 final List<Customer> floors= new ArrayList<Customer>(); jsonResponse = ""; for (int i = 0; i < response.length(); i++) { JSONObject c

我对安卓有点陌生。下面是我的代码。我在这里使用了一个列表,我获取楼层编号,但得到重复的值

我将重复的值作为json数据存储在服务器中

请帮我从列表中删除重复的项目。谢谢大家

   final List<Customer> floors= new ArrayList<Customer>();
   jsonResponse = "";
   for (int i = 0; i < response.length(); i++) {
      JSONObject customer = (JSONObject) response.get(i);
      String email = customer.getString("email");
      String name = customer.getString("f_name");
      Double balance = customer.getDouble("balance");
      String phone = customer.getString("phone");
      String streetName = customer.getString("street");
      String wardName = customer.getString("ward");
      String doorNumber = customer.getString("door");
      String floorNumber = customer.getString("floor");
      String houseType=customer.getString("type");
      floors.add(new Customer(email, name, balance, doorNumber, phone, 
             streetName, houseType,wardName,floorNumber));
   }

例如,如果您想删除电子邮件字段上的重复项,可以使用HashMap。使用电子邮件作为HashMap的键,在插入客户之前,测试电子邮件是否存在,如下所示:

final Map<String, Customer> floorsMap= new HashMap<String,Customer>();
   jsonResponse = "";
   for (int i = 0; i < response.length(); i++) {
      JSONObject customer = (JSONObject) response.get(i);
      String email = customer.getString("email");
      String name = customer.getString("f_name");
      Double balance = customer.getDouble("balance");
      String phone = customer.getString("phone");
      String streetName = customer.getString("street");
      String wardName = customer.getString("ward");
      String doorNumber = customer.getString("door");
      String floorNumber = customer.getString("floor");
      String houseType=customer.getString("type");

      if(!floorsMap.containsKey(email)){
          floorsMap.put(email, new Customer(email, name, balance, doorNumber, phone, streetName, houseType,wardName,floorNumber));
      }
   }
   final List<Customer> floors = new ArrayList<Customer>(floorsMap.values());
final Map floorsMap=new HashMap();
jsonResponse=“”;
对于(int i=0;i
每个楼层由哪个字段标识?电子邮件?@kaushal,有用吗?
final Map<String, Customer> floorsMap= new HashMap<String,Customer>();
   jsonResponse = "";
   for (int i = 0; i < response.length(); i++) {
      JSONObject customer = (JSONObject) response.get(i);
      String email = customer.getString("email");
      String name = customer.getString("f_name");
      Double balance = customer.getDouble("balance");
      String phone = customer.getString("phone");
      String streetName = customer.getString("street");
      String wardName = customer.getString("ward");
      String doorNumber = customer.getString("door");
      String floorNumber = customer.getString("floor");
      String houseType=customer.getString("type");

      if(!floorsMap.containsKey(email)){
          floorsMap.put(email, new Customer(email, name, balance, doorNumber, phone, streetName, houseType,wardName,floorNumber));
      }
   }
   final List<Customer> floors = new ArrayList<Customer>(floorsMap.values());