0

I need to sort the products by High to Low & Low to High of its Price.I have done Low to High by using following code.But dont know how to implement High To Low?

Your answer is more appreciated...

 public static Comparator<Restaurant_Beam> strPriceFilterL2H = new Comparator<Restaurant_Beam>() {

      @Override
        public int compare(Restaurant_Beam lhs, Restaurant_Beam rhs) {
            int CompareResult = 0;
            if (Config.L2HFilterClicked == "L2H") {
                CompareResult = (int) Math.round(Double.parseDouble(lhs.getIG_SALES_PRICE()) - Double.parseDouble(rhs.getIG_SALES_PRICE()));

            } 
//Used else if for H2L.But did not get it as perfect

else if (Config.L2HFilterClicked == "H2L") {
                CompareResult = (int) Math.round(Double.parseDouble(lhs.getIG_SALES_PRICE()) + Double.parseDouble(rhs.getIG_SALES_PRICE()));

            }
            return CompareResult;
        }
    };

Use this

mMapFragment.getView().setClickable(false);

4

1 に答える 1

3

2 番目の比較式を次のように変更します。

CompareResult = (int) Math.round(Double.parseDouble(Double.parseDouble(rhs.getIG_SALES_PRICE()) - Double.parseDouble(lhs.getIG_SALES_PRICE()));

また、いくつかのことを指摘したいと思います

  • Doubleイプシロンとの比較を検討する
  • オブジェクトを比較する前にチェックすることをお勧めします
  • 比較するたびに解析するのは本当に悪い設計です。事前にどこかで値を解析しておくとよいでしょう。型を変更することを検討してください。現在、それは効率的ではありません。
于 2016-04-11T10:11:25.097 に答える