Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
112 views
in Technique[技术] by (71.8m points)

java - Delivery time appears empty

I made a simple if else statement that expects a delivery time and if it doesn't have it should be gone

The problem is that when it has a delivery time only the label appears but no the actual delivery time

This is my code:

if (!TextUtils.isEmpty(mProduct.deliveryPeriod)) {
            deliveryLinearLayout.setVisibility(View.VISIBLE);
            deliveryTimeTextViewSection.setVisibility(View.VISIBLE);
            deliveryTimeTextViewLabel.setVisibility(View.VISIBLE);

            SpannableStringBuilder deliveryBuilder = formatDeliveryPeriod(mProduct.deliveryPeriod, R.color.dark_grayish_yellow);
            deliveryTimeTextView.setText(deliveryBuilder);

            deliveryTimeTextViewSection.setText(mProduct.deliveryPeriod);
            deliveryTimeTextViewSection.setPaintFlags(deliveryTimeTextViewSection.getPaintFlags() | Paint
                    .UNDERLINE_TEXT_FLAG);
        } else {
            deliveryLinearLayout.setVisibility(View.GONE);
            deliveryTimeTextViewSection.setVisibility(View.GONE);
            deliveryTimeTextViewLabel.setVisibility(View.GONE);
        }

The deliveryTimeTextViewLabel is the label that is appearing but i'm not getting the actual delivery time even though i did deliveryTimeTextView.setText(deliveryBuilder);

function formatDeliveryPeriod :

private SpannableStringBuilder formatDeliveryPeriod(@NonNull final String period, int colorResource) {
        final String deliveryContent = getString(R.string.template_delivery_period) + " " + period;
        SpannableStringBuilder builder = new SpannableStringBuilder();

        int color;
        int start;
        if (mPresenter.isDeliveryTimeHighlighted()) {
            color = mPresenter.getMessageLineColor();
            start = 0;
        } else {
            color = ContextCompat.getColor(this, colorResource);
            start = deliveryContent.lastIndexOf(period);
        }

        builder.append(deliveryContent);
        builder.setSpan(new ForegroundColorSpan(color), start, builder.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        builder.setSpan(new UnderlineSpan(), start, builder.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

        return builder;
    }
question from:https://stackoverflow.com/questions/65835859/delivery-time-appears-empty

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...