2017-02-28 43 views
0

我的ListView中的一些TextView受到Strike-Through效果的影響,其中只有那些具有「折扣價」的應該是具有Stripe-Through效果的TextView。原始價格與折扣價格的TextView不同。帶有Strike-Through Textviews的ListView中的Bug - ANDROID

這裏是我的代碼:

if(data.getDisc_price().equals("0")){ 
     holder.textDiscPrice.setVisibility(View.INVISIBLE); 
    } 
    else{ 
     holder.textPrice.setPaintFlags(holder.textPrice.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG); 
     holder.textDiscPrice.setText("Less " +data.getDisc_price()+"%" + " Php "+formatter.format(
       (Double.parseDouble(data.getPrice()) 
         -(Double.parseDouble(data.getPrice())*(Double.parseDouble(data.getDisc_price())/100))))); 

是什麼原因造成的錯誤?有任何想法嗎?

+1

你不是在'if'塊復位'Paint'標誌。 –

+0

謝謝先生。那麼它會是什麼樣子?我找到了一個答案,可能會指出你的解決方案。 [鏈接](http://stackoverflow.com/questions/18881817/removing-strikethrough-from-textview) –

+0

對。只需在if中的'holder.textPrice'上執行[this](http://stackoverflow.com/a/18882030)即可。 –

回答

0

由於@Mike M.

 if(data.getDisc_price().equals("0")){ 
       holder.textDiscPrice.setVisibility(View.INVISIBLE); 
    /*SOLUTION*/ holder.textPrice.setPaintFlags(tv.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG)); 
      } 
      else{ 
       holder.textPrice.setPaintFlags(holder.textPrice.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG); 
       holder.textDiscPrice.setText("Less " +data.getDisc_price()+"%" + " Php "+formatter.format(
         (Double.parseDouble(data.getPrice()) 
           -(Double.parseDouble(data.getPrice())*(Double.parseDouble(data.getDisc_price())/100)))));