0

Some of the TextViews in my ListView are affected by the Strike-Through effect wherein only those with "Discounted Price" should be the ones With Strike-Through effect.The TextView of the Original Price is Different from the TextView of the Discounted Price.

Here is my code:

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

What causes the bug? Any Ideas?

  • 1
    You're not resetting the `Paint` flags in the `if` block. – Mike M. Feb 28 '17 at 18:25
  • Thank you sir. Then what would it look like? I've found an answer that would might point out your solution. [link](http://stackoverflow.com/questions/18881817/removing-strikethrough-from-textview) – Claude Dubouzet Feb 28 '17 at 18:30
  • Right. Just do [this](http://stackoverflow.com/a/18882030) on `holder.textPrice` in the `if`. – Mike M. Feb 28 '17 at 18:32

1 Answers1

0

Thanks to @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)))));