Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 复数不';不能在xml中工作_Android_Android Databinding - Fatal编程技术网

Android 复数不';不能在xml中工作

Android 复数不';不能在xml中工作,android,android-databinding,Android,Android Databinding,我正在尝试在我的textinputtext中的错误文本中加载复数: <android.support.design.widget.TextInputEditText android:id="@+id/et_subject_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textCapWords" andr

我正在尝试在我的
textinputtext
中的错误文本中加载复数:

<android.support.design.widget.TextInputEditText
    android:id="@+id/et_subject_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textCapWords"
    android:lines="1"
    android:maxLines="1"
    android:singleLine="true"
    android:text="@{ model.name }"
    android:hint="@string/hint_name"
    app:validateRegex='@{"^*\\S{2}.*$"}'
    app:validateRegexMessage="@{@plurals/error_too_short(model.minNameLength)}"/>
怎么了?还是用另一种方式在xml中显示复数?

另外,如果数据绑定引擎V2很重要,我会使用它。

它应该是这样的:

<plurals name="recent_messages">
    <item quantity="zero">No Recent Messages</item>
    <item quantity="one">1 Recent Message</item>
    <item quantity="other">%1$d Recent Messages</item>
</plurals>

mContext.getResources().getQuantityString(R.plurals.recent_messages, count, count);

没有最近的消息
1最近的信息
%1$d最近的消息
mContext.getResources().getQuantityString(R.plurals.recent_messages,count,count);
在官方:

使用该方法时,如果字符串包含 使用数字设置字符串格式。例如,对于字符串 %如果找到d首歌曲,则第一个count参数选择适当的复数字符串,然后 第二个计数参数插入到%d占位符中。如果你的复数 字符串不包括字符串格式,您不需要将第三个参数传递给

因此,如果希望
model.minNameLength
定义要选择的复数版本以及在字符串中插入其值,则应该提供两次。因此,数据绑定表达式应该如下所示:

app:validateRegexMessage="@{@plurals/error_too_short(model.minNameLength, model.minNameLength)}"

您可以使用
%d
。回答得不错。荣誉
app:validateRegexMessage="@{@plurals/error_too_short(model.minNameLength, model.minNameLength)}"