Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么collections.sort()正在更改它正在排序的项目的属性?_Android_Facebook_List_Sorting_Contact - Fatal编程技术网

Android 为什么collections.sort()正在更改它正在排序的项目的属性?

Android 为什么collections.sort()正在更改它正在排序的项目的属性?,android,facebook,list,sorting,contact,Android,Facebook,List,Sorting,Contact,我正在尝试在使用Facebook API的android应用程序中对Facebook联系人列表进行排序。第一部分应该是在线联系人(按字母顺序排列),第二部分是离线联系人(也按字母顺序排列)。因此,我实现了Comparable接口,并在类中为需要排序的项重写compareTo() public class FBRowItem implements Comparable { private Bitmap imageId; // pazi bese int, za R.resurs private

我正在尝试在使用Facebook API的android应用程序中对Facebook联系人列表进行排序。第一部分应该是在线联系人(按字母顺序排列),第二部分是离线联系人(也按字母顺序排列)。因此,我实现了Comparable接口,并在类中为需要排序的项重写compareTo()

public class FBRowItem implements Comparable {

private Bitmap imageId; // pazi bese int, za R.resurs
private String contactName;
private String userName;
private Boolean isAvailable;

public FBRowItem() {
    this.imageId=null;
    this.contactName=null;
    this.userName=null;
    this.isAvailable=false;
}
public FBRowItem(Bitmap imageId, String contactName, String userName, Boolean isAvailable) {
    this.imageId = imageId;
    this.contactName=contactName;
    this.userName = userName;
    this.isAvailable=isAvailable;
}

public Bitmap getImageId() {
    return imageId;
}
public void setImageId(Bitmap imageId) {
    this.imageId = imageId;
}
public String getContactName() {
    return contactName;
}
public void setContactName(String contactName) {
    this.contactName=contactName;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName=userName;
}
public Boolean getIsAvailable (){
    return isAvailable;
}
public void setIsAvailable (Boolean isAvailable){
    this.isAvailable=isAvailable;
}

@Override
public String toString() {
    return contactName;
}
@Override
public int compareTo(Object arg0) {
    FBRowItem f = (FBRowItem) arg0;

    if((this.getIsAvailable()).equals(true)){
        if((f.getIsAvailable()).equals(true))
            return this.contactName.compareTo(f.contactName);
        else return -1;
    }
    else{
        if((f.getIsAvailable()).equals(true))
            return +1;
        else
            return this.contactName.compareTo(f.contactName);
    }



    // return this.contactName.compareTo(f.contactName);
}

}
下面是我调用的对联系人进行排序的方法

public static void receiveAllFBContacts(Context context){

    rowItems = FB_FriendsActivity.friendsList(context);
    Collections.sort(rowItems); 

}
正如您在compareTo()方法中所看到的,如果我使用的最后一行实际上目前只是一条注释,那么Collections.sort(rowItems)工作得很好,因此我对所有联系人进行了排序,但没有将联机和脱机分开。 问题:但是,如果我使用如上所示的未注释部分,Collection.sort(rowItems)会因某种原因将所有联系人的状态更改为在线。尝试阅读一些文档,但无法进一步阅读。欢迎任何帮助


(rowItems是ArrayList“”)

您发布的代码不会导致您看到的行为。我建议去别处看看。从调试开始。在setIsAvailable方法中放置一个断点,看看到底是什么改变了状态。(这不是你的分类。)

你发布的代码不会导致你看到的行为。我建议去别处看看。从调试开始。在
setIsAvailable
方法中放置一个断点,查看实际改变状态的是什么。(这不是你的分类。)你是对的,实际状态甚至没有改变。问题出在适配器上。我所做的是,当getIsAvailable()返回true时,我只在适配器中将联系人的状态设置为online。否则我什么也不做,因为我将ImageView状态预定义为脱机红色圆圈。不知何故,它可能是动态更改的,我必须从适配器显式地将图片更改为脱机。我不知道stackoverflow是如何工作的,但你可以发布你的答案,我会标记它。:)我很高兴你解决了你的问题。我已经发表了我的评论,作为对你问题的回答。