Android 将动态字符串资源传递给;吐司;
我正在尝试向“Toast”传递一个动态字符串 我做了一个定制的功能:Android 将动态字符串资源传递给;吐司;,android,Android,我正在尝试向“Toast”传递一个动态字符串 我做了一个定制的功能: private void makeToast(String message) { Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } 然后我可以使用此函数传递Toast消息,如: makeToast("You must enter the PIN code for authentication."); 我现在试图实现的是向它传递
private void makeToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
然后我可以使用此函数传递Toast消息,如:
makeToast("You must enter the PIN code for authentication.");
我现在试图实现的是向它传递一个动态字符串。
所以我在strings.xml中声明了它,比如:
<string name="must_pin">You must enter the PIN code for authentication</string>
但是它不接受它,并且说它不能接受“int”。。。。那么我怎样才能把这个传给MakeToos呢。正确的格式是什么?按照当前的格式,您只传递引用ID。您需要使用
getString()
是一个int,您的方法需要一个字符串
您需要使用getResources().getString(…)
R.string.must\u pin
是一个int变量。您应该使用getResources().getString()
访问String.xml
文件中定义的String
s
makeToast(R.string.must_pin);
makeToast(getString(R.string.must_pin));
R.string.must_pin
makeToast(getResources().getString(R.string.must_pin));
makeToast(getResources().getString(R.string.must_pin));