BulletSpan无法在Android Textview中运行

时间:2015-11-20 07:07:30

标签: android html textview bullet-span

我尝试使用unorderedBulletSpan.列表添加项目符号但是,我在列表中找不到项目符号。以下是我的代码:

private static String appendBullet(int leadingMargin, String liText) {
    SpannableString spannableString = new SpannableString(liText);
    spannableString.setSpan(new BulletSpan(leadingMargin), 0, liText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    Log.d("Ul tags", String.valueOf(spannableString));
    return spannableString.toString();
}

此处liItext是列表项。我在此处添加BulletSpan,然后返回该项并将其添加到list,最后将整个列表添加到StringBuilder

liList.add(appendBullet(15, liText));

List<String> liList = addListWithBullets(lists, new ArrayList<String>());

if (liList.size() > 0) {
    for (String str : liList) {
        builder.append(str);
        builder.append("<br/>");
    }
    Log.d("Ul tags", String.valueOf(liList));
}

1 个答案:

答案 0 :(得分:0)

首先,您可能想使用SpannableStringBuilder而不是StringBuilder。其次,在appendBullet(...)实例上调用toString()的{​​{1}}方法中,您可能会丢失所有扩展信息!您可能要做的是将每个要SpannableString加上符号的String附加到SpannableStringBuilder实例上,然后在setSpan(...)实例上为每个SpannableStringBuilder实例调用String方法SpannableStringBuilder

如果有帮助,我在<div class="col-md-4 col-sm-6 col-xs-12"> <div class=" wpcf7-list-item" id="voucher_150"> <input type="checkbox" name="checkbox-680" value="150" id="Product50" onclick="enableQuantity('Product50','QuantityProd5');""> <span class="wpcf7-list-item-label 150guts">150€ Voucher x </span> <select name="form[QuantityProd5][]" id="QuantityProd5" onchange="calculateTotal();" class="rsform-select-box"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <span>&nbsp;Stück</span> </div> </div> <div class="col-md-4 col-sm-6 col-xs-12"> <div class=" wpcf7-list-item" id="voucher_200"> <input type="checkbox" name="checkbox-680" value="200" id="Product60" onclick="enableQuantity('Product60','QuantityProd6');""> <span class="wpcf7-list-item-label 150guts">200€ Voucher x </span> <select name="form[QuantityProd6][]" id="QuantityProd6" onchange="calculateTotal();" class="rsform-select-box"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <span>&nbsp;Stück</span> </div> </div> <div id="t_area"> <textarea id="get_checked"></textarea> </div> 类上集成了一个扩展函数,可以为您消除一些困难。您可以找到.update