[英]Facebook SDK 3: how to sort friends list alphabetically (Android)
Using the Facebook SDK 3
, I am getting the list of GraphUser
of my friends list, but when I put it into a custom ListView
everyone is out of order. 使用
Facebook SDK 3
,我得到了我的朋友列表的GraphUser
列表,但是当我将其放入自定义ListView
每个人都处于GraphUser
状态。
Does the SDK have a way to sort the list by first name alphabetically? SDK是否可以按名字的字母顺序对列表进行排序? I have tried to do
Collections.sort
but it doesn't recognize GraphUser
. 我尝试做
Collections.sort
但它不识别GraphUser
。
HELP! 救命!
Get FB Friends and put them in List GraphUser, which is then passed to ArrayAdapter 获取FB Friends,并将其放入List GraphUser中,然后将其传递给ArrayAdapter
private List<GraphUser> fbFriends;
private void requestFacebookFriends(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
fbFriends = getResults(response);
FriendsListAdapter adapter = new FriendsListAdapter(PickFriendActivity.this, R.layout.listview_row_friend, fbFriends);
listView.setAdapter(adapter);
}
});
friendsRequest.executeAsync();
}
private Request createRequest(Session session) {
Request request = Request.newGraphPathRequest(session, "me/friends", null);
Set<String> fields = new HashSet<String>();
String[] requiredFields = new String[] {"id", "name", "picture"};
fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
private List<GraphUser> getResults(Response response) {
GraphMultiResult multiResult = response.getGraphObjectAs(GraphMultiResult.class);
GraphObjectList<GraphObject> data = multiResult.getData();
return data.castToListOf(GraphUser.class);
}
UPDATED w/ ANSWER 带答案的更新
private class FriendComparator implements Comparator<Friend> {
@Override
public int compare(Friend user1, Friend user2) {
return user1.getFbName().compareTo(user2.getFbName());
}
}
Collections.sort(fbFriends, new FriendComparator());
使用具有比较器对象的Collection.sort,并为GraphUsers定义一个比较器,以比较名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.