2017-01-18 10 views
0

最低距離の順にレルム結果を注文するには、それを行う必要があります。だから私はそれを行う:このカスタムRealmResultをソートする方法?

  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() 

       } 
      }); 

     } 

問題はレルムがこのリストを並べ替えていないので、アダプタで、私は距離順空港を持っていないということです。

良い方法がありますか? おかげ分野の新しいアップデートで

+1

'nearbs = nearbs.sort( "距離"、Sort.ASCENDING)を一覧表示するには、ソート結果を割り当てることになっている;'王国の新しいアップデートでは、ソートされた結果をリスト –

答えて

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

、あなたが

+0

リストに割り当てることになっています。 – ste9206

関連する問題