Java 在Android中将正则表达式%1$d转换为字符串

Java 在Android中将正则表达式%1$d转换为字符串,java,android,string-formatting,spannablestring,Java,Android,String Formatting,Spannablestring,我每月有存款\n$%1$d,我知道这是因为%1$d我不能像字符串一样显示它。但我不知道如何正确格式化,尽管在互联网上有很多例子,我可以绕着它转。我不知道如何使用%1$d 从android中的字符串文件夹开始格式化它 public void binding(final OtherAccModel modelClass) { binding.setOther(modelClass); binding.executePendingBindings();

我每月有
存款\n$%1$d
,我知道这是因为
%1$d
我不能像字符串一样显示它。但我不知道如何正确格式化,尽管在互联网上有很多例子,我可以绕着它转。我不知道如何使用
%1$d
从android中的字符串文件夹开始格式化它

 public void binding(final OtherAccModel modelClass) {
        binding.setOther(modelClass);
        binding.executePendingBindings();


        setSpannableTextWithColor(binding.policyTV, R.string.policy_account_number_other, modelClass.getPolicy(), Color.BLACK);
        setSpannableTextWithColor(binding.companyNameTV,R.string.company_name_other,modelClass.getCompanyName(), Color.BLACK);
        setSpannableTextWithColor(binding.monthlySavingsTV,R.string.monthly_savings_other, String.valueOf(modelClass.getMonthlySavings()), Color.BLACK);
        setSpannableTextWithColor(binding.rorTV,R.string.return_of_value_other, String.valueOf(modelClass.getRor()), Color.BLACK);
        setSpannableTextWithColor(binding.accNameTV,R.string.type_other,modelClass.getType(), Color.BLACK);
        setSpannableTextWithColor(binding.accValueTV,R.string.current_value_other, String.valueOf(modelClass.getCurrentValue()), Color.BLACK);
    }

    void setSpannableTextWithColor(TextView view, int resourceId, String string, int color) {
        if (string == null)
            return;
        String fulltext = context.getResources().getString(resourceId, string);
        String part = string;
        SpannableString str = new SpannableString(fulltext);
        str.setSpan(new ForegroundColorSpan(color), fulltext.length() - part.length(), fulltext.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        view.setText(str);
    }
在线
String fulltext=context.getResources().getString(resourceId,String)我收到错误消息

java.util.IllegalFormatConversionException: d != java.lang.String

使用%1$s而不是%1$d

d将数字格式化为十进制数字,并且只能与整数一起使用

欲了解更多信息,请阅读