I am trying to create an error dialog that says "Wrong input : input". My problem - "Wroing input" is pre-defined in the string file and thus have R.string.error int number. The "input" is dynamic and I can only obtain it in runtime. the setMessage() method can work with either a char sequence or an int (for id), so how can I concat it? Hope I was clear, thanks!
You can call getString to obtain the string from the xml:
String msg = getString(R.string.error) + myDynamicStringMessage;
Note that getString is a context method, so make sure to call it from one.
如果我对您的理解正确,那么您应该能够创建一个String变量,其中“错误的输入”和“ input”已连接在一起,然后只需将该String传递给setMessage()方法即可。
Use getString() to obtain string from xml
you can use setMessage(getString(R.string.error)+" My Dynamic Message")
new AlertDialog.Builder(this).setMessage(getString(R.string.error)+" My Dynamic Message")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
}).setNegativeButton("NO", null).show();
Thanks Deepak
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.