【问题标题】:Bug in ListView with Strike-Through Textviews - ANDROID带有 Strike-Through Textviews 的 ListView 中的错误 - ANDROID
【发布时间】:2017-02-28 18:23:37
【问题描述】:

我的 ListView 中的一些 TextView 受到 Strike-Through 效果的影响,其中只有那些具有“折扣价”的应该是具有 Strike-Through 效果的那些。原始价格的 TextView 与折扣的 TextView 不同价格。

这是我的代码:

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

是什么导致了这个错误?有什么想法吗?

【问题讨论】:

  • 您没有重置 if 块中的 Paint 标志。
  • 谢谢先生。那么它会是什么样子呢?我找到了一个可能会指出您的解决方案的答案。 link
  • 对。只需在if 中的holder.textPrice 上执行this

标签: android listview


【解决方案1】:

感谢@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)))));

【讨论】:

    猜你喜欢
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多