在string资源中添加变量
public void checkModeByAction() {
if(TxrjConstant.ACTION_ADD_RECIPIENT.equals(getIntent().getAction())) {
mode = Mode.MODE_SELECT;
mSelectOk = (Button)findViewById(R.id.select_ok);
mSelectAll = (Button)findViewById(R.id.select_all);
}
}
public void updateSelectButtonText() {
int count = 0;
int size = mContacts.size();
for(int i=0;i<size;i++) {
if(mContacts.get(i).isSelected())
count++;
}
updateSelectButtonText(count);
}
public void updateSelectButtonText(int count) {
String txtSelectOk = getResources().getString(R.string.contact_select_ok);
String.format(txtSelectOk, count);
mSelectOk.setText(txtSelectOk);
String txtSelectAll = getResources().getString(
count == mContacts.size() ? R.string.contact_unselect_all
: R.string.contact_select_all);
mSelectAll.setText(txtSelectAll);
}
如果按照如下定义
<string name="contact_select_ok">ok(%1$d)</string>
结果显示仍然是ok(%1$d)
是不是括号的缘故呢?
很奇怪,将小括号去掉,或将小括号改成中括号,也会出现这个问题
再将%1$d改成%d,还是有这个问题
真活该,很低级的错误
将上面红色的两条代码第2条代码修改
String txtSelectOk = getResources().getString(R.string.contact_select_ok);
txtSelectOk = String.format(txtSelectOk, count);
再执行就符合预期效果