Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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 如何对此自定义RealmResult进行排序?_Android_Realm - Fatal编程技术网

Android 如何对此自定义RealmResult进行排序?

Android 如何对此自定义RealmResult进行排序?,android,realm,Android,Realm,我需要按照最小距离的顺序排列我的领域结果。因此,我这样做: public void onNext(final Location location) { latitude = location.getLatitude(); longitude = location.getLongitude(); nearbs = realm.where(Airport.class).greaterThanO

我需要按照最小距离的顺序排列我的领域结果。因此,我这样做:

         public void onNext(final Location location)
        {
            latitude = location.getLatitude();
            longitude = location.getLongitude();

            nearbs = realm.where(Airport.class).greaterThanOrEqualTo("latitudeDeg",(latitude - 0.5)).lessThanOrEqualTo("latitudeDeg",(latitude + 0.5))
                    .greaterThanOrEqualTo("longitudeDeg",longitude - 0.5).lessThanOrEqualTo("longitudeDeg",longitude + 0.5).findAll();


            realm.executeTransaction(new Realm.Transaction() {
                @Override
                public void execute(Realm realm)
                {
                    for(Airport airport : nearbs)
                    {
                        Location location1 = new Location("");
                        location1.setLatitude(airport.getLatitudeDeg());
                        location1.setLongitude(airport.getLongitudeDeg());

                        float distance = location1.distanceTo(location);
                        distance = distance/1852; //Calculate the distance

                        airport.setDistance(distance);
                        Log.d("distance",String.valueOf(distance));

                        realm.insertOrUpdate(airport);
                    }

                    nearbs.sort("distance", Sort.ASCENDING);

                    adapter.updateNearbs(nearbs); //here there is notifyDataSetChanged()

                }
            });

        }
问题是Realm没有对这个列表进行排序,所以在adapter中,我没有按距离对机场进行排序

有更好的方法吗? 谢谢

在新的领域更新中,您应该将排序结果分配给列表

nearbs=nearbs.sortdistance,Sort.升序;在新的领域更新中,您应该将排序结果分配给列表
nearbs = nearbs.sort("distance", Sort.ASCENDING);