我想在这里为 String
资源做同样的事情:
write(String.format(getString(R.string.night), "Scurcola"));
但对于 String Array
,定义如下:
<string-array name="goodMorning" formated="false">
<item>Good Morning folks!</item>
<item>Sun\'s out, guns out.</item>
<item>Careless vampires burn, and you wake up!</item>
<item>Can\'t find the moon. Oh it\'s probably morning then..</item>
<item>Darkness flees from %s, wake up!</item>
<item>Sunlight manifests, it\'s morning %s!</item>
<item>Stars went to bed, and %s wakes up!</item>
<item>Be beep. Be beep. %s wake up!</item>
</string-array>
我怎样才能做到这一点?
答案 0 :(得分:1)
我解决了这个问题,添加了编辑def iterate(m):
for row in range(0,4):
for col in range(0,4):
print(m[row-1][col+1]+
m[row][col+1]+
m[row+1][col-1]+
m[row+1][col]+
m[row+1][col+1])
mat=[
["A","B","C","D",""],
["E","F","G","H",""],
["I","J","K","L",""],
["M","N","O","P",""],
["", "", "", "", ""]
]
iterate(mat)
:
TextView
这样我只需输入:
public void write(int id, int position, String text){
String[] msg = getResources().getStringArray(id);
messages.add(String.format(msg[position], text));
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, messages);
screen.setAdapter(adapter);
}
并输出 write(R.array.goodMorning, randInt(0, 7), "Scurcola");
item
,随机,因此格式化与&#34; Scurcola &#34; String Array
我以String
传递。
答案 1 :(得分:0)
每个数组项本身实际上都是一个字符串 因此,每个项目都可以单独格式化。
即:
write(String.format(getResources().getStringArray(R.array.goodMorning)[0], "Scurcola"));