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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…