关闭

Android开发合并相同通话记录并显示通话记录条数

312人阅读 评论(0) 收藏 举报
分类:

CommonUtil.java

public class CommonUtil {

public static List<ContactInfo> handleList(List<ContactInfo> list) {
Map<String, Integer> map = new HashMap<String, Integer>();
ArrayList<ContactInfo> result = new ArrayList<ContactInfo>();
for (int i = 0; i < list.size(); i++) {
int k = 1;
for (int j = i + 1; j < list.size(); j++) {
if (list.get(i).getPhoneNum().equals(list.get(j).getPhoneNum())) {
k++;
} else {
continue;
}
}
if (!map.containsKey(list.get(i).getPhoneNum()))
map.put(list.get(i).getPhoneNum(), k);
}
Set<Entry<String, Integer>> entrySet = map.entrySet();
Iterator<Entry<String, Integer>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
for (int i = 0; i < map.size(); i++) {
Entry<String, Integer> next = iterator.next();
for (int j = 0; j < list.size(); j++) {
if (next.getKey().equals(list.get(j).getPhoneNum())) {
list.get(j).setNumber(String.valueOf(next.getValue()));
result.add(list.get(j));
break;
}
}


}


}
return result;
}

}


ContactInfo.java

package com.ran.wedial.info;


public class ContactInfo {


private Long id;
private String name;
private String formattedNumber;
private String phoneNum;
private String pinyin;
private int type;
private String date;
private String Numbers;


public Long getId() {
return id;
}


public void setId(Long id) {
this.id = id;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public String getFormattedNumber() {
return formattedNumber;
}


public void setFormattedNumber(String formattedNumber) {
this.formattedNumber = formattedNumber;
}


public String getPhoneNum() {
return phoneNum;
}


public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}


public String getPinyin() {
return pinyin;
}


public void setPinyin(String pinyin) {
this.pinyin = pinyin;
}


public int getType() {
return type;
}


public void setType(int type) {
this.type = type;
}


public String getDate() {
return date;
}


public void setDate(String date) {
this.date = date;
}


public void setNumber(String Numbers) {
this.Numbers = Numbers;
}


public String getNumbers() {
return Numbers;
}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:321次
    • 积分:14
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档