我正在分析instagram关注者和关注者。我要添加适配器,该适配器可以追随用户并追随用户。
我的代码:
ArrayList<InstagramUserSummary> mutuals = new ArrayList<>(followers);
for (InstagramUserSummary i : followers) {
for (InstagramUserSummary j : following) {
if (i.equals(j)) {
WHAT I HAVE TO DO HERE TO SET ADAPTER mutuals?
}
}
}
答案 0 :(得分:1)
要获取“关注者”和“关注者”之间的交集,请使用
Collection#retainAll()。
listA.retainAll(listB);
// listA now contains only the elements which are also contained in listB.
如果要避免listA中的更改受到影响,则需要创建一个新的更改。
List<Integer> common = new ArrayList<Integer>(listA);
common.retainAll(listB); // common now contains only the elements which are contained in listA and listB.
答案 1 :(得分:0)
ArrayList<InstagramUserSummary> mutuals = new ArrayList<>();
for (InstagramUserSummary i : followers) {
for (InstagramUserSummary j : following) {
if (i.equals(j)) {
mutuals.add(i);
}
}
}
// here use mutuals to create Adapter
// change this code and use your custom adapter to show users detail in list
ArrayAdapter<InstagramUserSummary> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, mutuals);