Creating dialog in java/android
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 co开发者_开发知识库ncat 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.
If I understand you correctly, you should be able to create a String variable in which "wrong input" and "input" have been concatenated, then simply pass that String to the setMessage() method.
Use getString() to obtain string from xml
you can use setMessage(getString(R.string.error)+" My Dynamic Message")
Example
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
精彩评论