2017-04-06 198 views
0

變化的數據我有了市場有回​​收視圖,所以填充的AsyncTask和清涼被稱爲每3秒。我想要的是,如果某個列的值在回收站中發生變化,我希望它在幾分之一秒內突出顯示,那麼知道我們無法重寫notifyDataSetChanged方法,該怎麼做呢?跟蹤舊的數組列表並將其中的每個項目與新項目進行比較是不可行的,所以如果您有一個有價值的解決方案,請提供給我。突出顯示RecyclerView

+0

['DiffUtils'(https://developer.android.com/reference/android/support/v7/util/DiffUtil.html)將幫助你瞭解哪些項目有被改變了。 – azizbekian

+0

有沒有樣品或東西? –

+0

[這是](https://medium.com/@nullthemall/diffutil-is-a-must-797502bc1149)一個不錯的。 – azizbekian

回答

0

解決它

  //<editor-fold desc="highlighting section"> 
      OnlineOrder oldOrder = oldAllOrders.get(position); 
      OnlineOrder newOrder = newAllOrders.get(position); 

      if (oldOrder.getId() == newOrder.getId()){ 
       //compare here 
       //holder.tvPortfolioItem.setTextColor(newOrder.getPortfolioNumber().equals(oldOrder.getPortfolioNumber()) ? Color.BLACK : Color.RED); 
       //holder.tvPriceItem.setTextColor(newOrder.getPrice() == oldOrder.getPrice() ? Color.BLACK : Color.RED); 
       //holder.tvDateTimeItem.setTextColor(newOrder.getOrderDateTime().equals(oldOrder.getOrderDateTime()) ? Color.BLACK : Color.RED); 

       if (!newOrder.getPortfolioNumber().equals(oldOrder.getPortfolioNumber())){ 

        int colorFrom = Color.RED ; 
        int colorTo = Color.BLACK ; 
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); 
        colorAnimation.setDuration(2000); // milliseconds 
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

         @Override 
         public void onAnimationUpdate(ValueAnimator animator) { 
          holder.tvPortfolioItem.setTextColor((int) animator.getAnimatedValue()); 
         } 

        }); 
        colorAnimation.start(); 
       } 

       if (newOrder.getPrice() != oldOrder.getPrice()){ 

        int colorFrom = Color.RED ; 
        int colorTo = Color.BLACK ; 
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); 
        colorAnimation.setDuration(2000); // milliseconds 
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

         @Override 
         public void onAnimationUpdate(ValueAnimator animator) { 
          holder.tvPriceItem.setTextColor((int) animator.getAnimatedValue()); 
         } 

        }); 
        colorAnimation.start(); 
       } 


       if (!newOrder.getOrderDateTime().equals(oldOrder.getOrderDateTime())){ 

        int colorFrom = Color.RED ; 
        int colorTo = Color.BLACK ; 
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); 
        colorAnimation.setDuration(2000); // milliseconds 
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 

         @Override 
         public void onAnimationUpdate(ValueAnimator animator) { 
          holder.tvDateTimeItem.setTextColor((int) animator.getAnimatedValue()); 
         } 

        }); 
        colorAnimation.start(); 
       } 
      } 
      //</editor-fold>