Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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 将动态字符串资源传递给;吐司;_Android - Fatal编程技术网

Android 将动态字符串资源传递给;吐司;

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."); 我现在试图实现的是向它传递

我正在尝试向“Toast”传递一个动态字符串

我做了一个定制的功能:

  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));